// NewUnixSock creates an UnixSock from a string path.  String can be in the
// form of either URI-based string (e.g. `file:///etc/passwd`), an absolute
// path (e.g. `/etc/passwd`), or a relative path (e.g. `./foo`).
171048
func NewUnixSock(s string) (ret UnixSock, err error) {
	ret.path = s
	return ret, nil
}
1362898
func NewMux() *http.ServeMux {
	mux := http.NewServeMux()
	mux.HandleFunc(BasePath+"/", func(w http.ResponseWriter, r *http.Request) {
		// this endpoint, as implemented in the standard library, doesn't set
		// its Content-Type header, so using this can confuse clients, especially
		// if gzipping...
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
		pp.Index(w, r)
	})
	mux.HandleFunc(BasePath+"/cmdline", pp.Cmdline)
	mux.HandleFunc(BasePath+"/profile", pp.Profile)
	mux.HandleFunc(BasePath+"/symbol", pp.Symbol)
	mux.HandleFunc(BasePath+"/trace", pp.Trace)
	return mux
}
543497
func NewgidmapPath(newgidmapPath string) func(*LinuxFactory) error {
	return func(l *LinuxFactory) error {
		l.NewgidmapPath = newgidmapPath
		return nil
	}
}
1243443
func newRandomID(n int) string {
	rand.Seed(UTCNow().UnixNano())
	sid := make([]rune, n)
	for i := range sid {
		sid[i] = letters[rand.Intn(len(letters))]
	}
	return string(sid)
}
1260388
func NewPathsWithDefaults(p Paths) Paths {
	paths := DefaultPaths
	if p.DataDir != "" {
		paths.DataDir = p.DataDir
	}
	if p.LogDir != "" {
		paths.LogDir = p.LogDir
	}
	if p.MetricsSpoolDir != "" {
		paths.MetricsSpoolDir = p.MetricsSpoolDir
	}
	if p.ConfDir != "" {
		paths.ConfDir = p.ConfDir
	}
	return paths
}
232524
func NewUnixSocket(path string, gid int) (net.Listener, error) {
	return NewUnixSocketWithOpts(path, WithChown(0, gid), WithChmod(0660))
}
402458
func newUtils() *utilities {
	utils := make(map[string]command)
	utils["ast"] = dumpAst
	utils["callobj"] = dumpCallObj
	utils["uses"] = dumpUses
	utils["types"] = dumpTypes
	utils["defs"] = dumpDefs
	utils["comments"] = dumpComments
	utils["imports"] = dumpImports
	return &utilities{utils, make([]string, 0)}
}
159944
func newHTTPSink(u string, timeout time.Duration, headers http.Header, transport *http.Transport, listeners ...httpStatusListener) *httpSink {
	if transport == nil {
		transport = http.DefaultTransport.(*http.Transport)
	}
	return &httpSink{
		url:       u,
		listeners: listeners,
		client: &http.Client{
			Transport: &headerRoundTripper{
				Transport: transport,
				headers:   headers,
			},
			Timeout: timeout,
		},
	}
}
1050054
func parseUnixLike(l *lex, ua *UserAgent) bool {
	switch {
	case l.match("Linux") || l.match("Ubuntu"):
		ua.OS = OSLinux
	case l.match("FreeBSD"):
		ua.OS = "FreeBSD"
	case l.match("OpenBSD"):
		ua.OS = "OpenBSD"
	case l.match("NetBSD"):
		ua.OS = "NetBSD"
	case l.match("Maemo"):
		// FIXME: should it be GNU/Linux?
		ua.OS = "Maemo"
	case l.match("CrOS"):
		ua.OS = "CrOS"
	default:
		// Various distros use "... Distro; Linux x86_64) "
		if _, ok := l.spanBefore("Linux", ") "); ok {
			ua.OS = OSLinux
			return true
		}
		return false
	}
	return true
}
414388
func (a *AgentServer) ListenUnixSocket(path string, uid, gid int, mode os.FileMode) error {
	l, err := net.Listen("unix", path)
	if err != nil {
		return trace.Wrap(err)
	}
	if err := os.Chown(path, uid, gid); err != nil {
		l.Close()
		return trace.ConvertSystemError(err)
	}
	if err := os.Chmod(path, mode); err != nil {
		l.Close()
		return trace.ConvertSystemError(err)
	}
	a.listener = l
	a.path = path
	return nil
}
493536
func NewMock(req *Request, res *Response) *Mocker {
	mock := &Mocker{
		request:  req,
		response: res,
		matcher:  DefaultMatcher,
	}
	res.Mock = mock
	req.Mock = mock
	req.Response = res
	return mock
}
666431
func (n *Net) ListenUnix(nett string, laddr *net.UnixAddr) (*net.UnixListener, error) {
	if err := n.inherit(); err != nil {
		return nil, err
	}

	n.mutex.Lock()
	defer n.mutex.Unlock()

	// look for an inherited listener
	for i, l := range n.inherited {
		if l == nil { // we nil used inherited listeners
			continue
		}
		if isSameAddr(l.Addr(), laddr) {
			n.inherited[i] = nil
			n.active = append(n.active, l)
			return l.(*net.UnixListener), nil
		}
	}

	// make a fresh listener
	l, err := net.ListenUnix(nett, laddr)
	if err != nil {
		return nil, err
	}
	n.active = append(n.active, l)
	return l, nil
}
466586
func (engine *Engine) RunUnix(file string) (err error) {
	debugPrint("Listening and serving HTTP on unix:/%s", file)
	defer func() { debugPrintError(err) }()

	os.Remove(file)
	listener, err := net.Listen("unix", file)
	if err != nil {
		return
	}
	defer listener.Close()
	os.Chmod(file, 0777)
	err = http.Serve(listener, engine)
	return
}
328913
func NewUnixListener(ln net.Listener) *unixListener {
	return &unixListener{
		UnixListener:     ln.(*net.UnixListener),
		timeoutAccept:    time.Second * defaultTimeoutAcceptSeconds,
		timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds,
	}
}
99468
func NewCtx() (*Ctx, error) {
	c, err := NewCtxWithVersion(AnyVersion)
	if err == nil {
		c.SetOptions(NoSSLv2 | NoSSLv3)
	}
	return c, err
}
1289972
func NewFileSystemMock() *Mock {
	return &Mock{
		responses: make([]*WhenResp, 0),
		eventChan: make(chan fsnotify.Event),
	}
}
1354666
func NewMux() *Mux {
	return &Mux{
		// Default handler is a no-op
		DefaultHandler: HandlerFunc(func(ctx *Context, res *http.Response, err error) {}),
		errm:           make(map[error]Handler),
		res:            make(map[*ResponseMatcher]bool),
	}
}