// NetNsHandle returns a file descriptor handle for network namespace specified by PID.
// It returns error if network namespace could not be found or if network namespace path could not be opened.
168249
func NetNsHandle(nspid int) (uintptr, error) {
	if nspid <= 0 || nspid == 1 {
		return 0, fmt.Errorf("Incorred PID specified: %d", nspid)
	}

	nsPath := path.Join("/", "proc", strconv.Itoa(nspid), "ns/net")
	if nsPath == "" {
		return 0, fmt.Errorf("Could not find Network namespace for pid: %d", nspid)
	}

	file, err := os.Open(nsPath)
	if err != nil {
		return 0, fmt.Errorf("Could not open Network Namespace: %s", err)
	}

	return file.Fd(), nil
}
457533
func CmdlineHandler() echo.HandlerFunc {
	return func(ctx echo.Context) error {
		Cmdline(ctx)
		return nil
	}
}
4521
func (c *Client) callOnConnectHandlers() {
	c.m.RLock()
	defer c.m.RUnlock()

	for _, handler := range c.onConnectHandlers {
		func() {
			defer nopRecover()
			handler()
		}()
	}
}
197678
func Convert_network_NetNamespace_To_v1_NetNamespace(in *network.NetNamespace, out *v1.NetNamespace, s conversion.Scope) error {
	return autoConvert_network_NetNamespace_To_v1_NetNamespace(in, out, s)
}
224869
func IdentifyHandle(
	ctx context.Context, nug idutil.NormalizedUsernameGetter,
	identifier idutil.Identifier, osg idutil.OfflineStatusGetter,
	h *Handle) error {
	offline := keybase1.OfflineAvailability_NONE
	if osg != nil {
		offline = osg.OfflineAvailabilityForID(h.tlfID)
	}
	return identifyUsersForTLF(
		ctx, nug, identifier, h.ResolvedUsersMap(), h.Type(), offline)
}
1357127
func Convert_v1_NetNamespaceList_To_network_NetNamespaceList(in *v1.NetNamespaceList, out *network.NetNamespaceList, s conversion.Scope) error {
	return autoConvert_v1_NetNamespaceList_To_network_NetNamespaceList(in, out, s)
}
777775
func NewHandler(prefix string, opts Options, handleFunc func(Session)) http.Handler {
	return newHandler(prefix, opts, handleFunc)
}
181247
func NameHandler(name string, handler cfg.Handler) *HandlerName {
	return &HandlerName{
		Name:    name,
		Handler: handler,
	}
}
324926
func NewHandler() *Handler {
	h := &Handler{
		router: httprouter.New(),
		Logger: log15.New(),
	}
	h.router.POST("/clusters", h.servePostCluster)
	h.router.DELETE("/clusters", h.serveDeleteCluster)
	h.router.GET("/ping", h.serveGetPing)
	return h
}
983220
func (statics *AssestStruct) HttpHandler(pdir string) http.Handler {
	return &_assestFileServer{sf: statics, pdir: pdir}
}
1301342
func (pn *peernet) handleNewConn(c inet.Conn) {
	pn.RLock()
	handler := pn.connHandler
	pn.RUnlock()
	if handler != nil {
		go handler(c)
	}
}
765512
func (ss *StaticServer) DirectoryHandler(prefix, dirName string) http.Handler {
	if !strings.HasSuffix(prefix, "/") {
		prefix += "/"
	}
	idBase := dirName
	dirName = ss.resolve(dirName)
	return &staticHandler{
		ss: ss,
		id: func(p string) string {
			if !strings.HasPrefix(p, prefix) {
				return "."
			}
			return path.Join(idBase, p[len(prefix):])
		},
		open: func(p string) (io.ReadCloser, int64, string, error) {
			if !strings.HasPrefix(p, prefix) {
				return nil, 0, "", errors.New("request url does not match directory prefix")
			}
			p = p[len(prefix):]
			return ss.openFile(filepath.Join(dirName, filepath.FromSlash(p)))
		},
	}
}
1058836
func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error) {
	return newHandle(newNs, curNs)
}
77096
func NewUnaryHandler(params UnaryHandlerParams) transport.UnaryHandler {
	return newUnaryHandler(params.Handle, params.NewRequest)
}
664896
func (c *Spec) NewHandler(next http.Handler) (http.Handler, error) {
	return fromSpec(c, next)
}
1342868
func (pf *PortForwarder) handleConnection(conn net.Conn, port ForwardedPort) {
	defer conn.Close()

	glog.Infof("Handling connection for %d", port.Local)

	requestID := pf.nextRequestID()

	// create error stream
	headers := http.Header{}
	headers.Set(api.StreamType, api.StreamTypeError)
	headers.Set(api.PortHeader, fmt.Sprintf("%d", port.Remote))
	headers.Set(api.PortForwardRequestIDHeader, strconv.Itoa(requestID))
	errorStream, err := pf.streamConn.CreateStream(headers)
	if err != nil {
		util.HandleError(fmt.Errorf("error creating error stream for port %d -> %d: %v", port.Local, port.Remote, err))
		return
	}
	// we're not writing to this stream
	errorStream.Close()

	errorChan := make(chan error)
	go func() {
		message, err := ioutil.ReadAll(errorStream)
		switch {
		case err != nil:
			errorChan <- fmt.Errorf("error reading from error stream for port %d -> %d: %v", port.Local, port.Remote, err)
		case len(message) > 0:
			errorChan <- fmt.Errorf("an error occurred forwarding %d -> %d: %v", port.Local, port.Remote, string(message))
		}
		close(errorChan)
	}()

	// create data stream
	headers.Set(api.StreamType, api.StreamTypeData)
	dataStream, err := pf.streamConn.CreateStream(headers)
	if err != nil {
		util.HandleError(fmt.Errorf("error creating forwarding stream for port %d -> %d: %v", port.Local, port.Remote, err))
		return
	}

	localError := make(chan struct{})
	remoteDone := make(chan struct{})

	go func() {
		// Copy from the remote side to the local port.
		if _, err := io.Copy(conn, dataStream); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
			util.HandleError(fmt.Errorf("error copying from remote stream to local connection: %v", err))
		}

		// inform the select below that the remote copy is done
		close(remoteDone)
	}()

	go func() {
		// inform server we're not sending any more data after copy unblocks
		defer dataStream.Close()

		// Copy from the local port to the remote side.
		if _, err := io.Copy(dataStream, conn); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
			util.HandleError(fmt.Errorf("error copying from local connection to remote stream: %v", err))
			// break out of the select below without waiting for the other copy to finish
			close(localError)
		}
	}()

	// wait for either a local->remote error or for copying from remote->local to finish
	select {
	case <-remoteDone:
	case <-localError:
	}

	// always expect something on errorChan (it may be nil)
	err = <-errorChan
	if err != nil {
		util.HandleError(err)
	}
}
846676
func (s *storageRESTServer) RenameFileHandler(w http.ResponseWriter, r *http.Request) {
	if !s.IsValid(w, r) {
		return
	}
	vars := mux.Vars(r)
	srcVolume := vars[storageRESTSrcVolume]
	srcFilePath := vars[storageRESTSrcPath]
	dstVolume := vars[storageRESTDstVolume]
	dstFilePath := vars[storageRESTDstPath]
	err := s.storage.RenameFile(srcVolume, srcFilePath, dstVolume, dstFilePath)
	if err != nil {
		s.writeErrorResponse(w, err)
	}
}