// UNIX returns a new unix(file) Listener.
514441
func UNIX(socketFile string, mode os.FileMode) (net.Listener, error) {
	if errOs := os.Remove(socketFile); errOs != nil && !os.IsNotExist(errOs) {
		return nil, errRemoveUnix.Format(socketFile, errOs.Error())
	}

	l, err := net.Listen("unix", socketFile)
	if err != nil {
		return nil, errPortAlreadyUsed.AppendErr(err)
	}

	if err = os.Chmod(socketFile, mode); err != nil {
		return nil, errChmod.Format(mode, socketFile, err.Error())
	}

	return l, nil
}
618307
func DefaultSockPath() string {
	// Check if environment variable points to socket
	e := os.Getenv(defaults.SockPathEnv)
	if e == "" {
		// If unset, fall back to default value
		e = defaults.SockPath
	}
	return "unix://" + e

}
749132
func (fs *FS) File(inode uint32) (*File, error) {
	g, ioff, err := fs.igroup(inode)
	if err != nil {
		return nil, err
	}

	addr := int64(fs.BlockSize) * int64(g.Inodeaddr+ioff/fs.inodesPerBlock)
	ivoff := (ioff % fs.inodesPerBlock) * fs.inodeSize

	file := &File{fs: fs, inum: inode}
	if _, err := fs.read(addr, int(ivoff), &file.ino); err != nil {
		return nil, err
	}

	switch file.ino.Mode & ifmt {
	case ififo, ifchr, ifdir, ifblk, ifreg, iflnk, ifsock:
		// okay
	default:
		return nil, fmt.Errorf("invalid inode mode %#x", file.ino.Mode)
	}

	return file, nil
}
377639
func (s *ProxyServer) ListenUnix(path string) (net.Listener, error) {
	// Remove any socket, stale or not, but fall through for other files
	fi, err := os.Stat(path)
	if err == nil && (fi.Mode()&os.ModeSocket) != 0 {
		os.Remove(path)
	}
	// Default to only user accessible socket, caller can open up later if desired
	oldmask, _ := util.Umask(0077)
	l, err := net.Listen("unix", path)
	util.Umask(oldmask)
	return l, err
}
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
}
1329423
func unixAttrInit() {
	// Sorted for human readability
	unixAttrs = []AttrName{
		"path",
	}

	unixAttrMap = map[AttrName]func(us UnixSock) string{
		"path": func(us UnixSock) string {
			return us.Path()
		},
	}
}
130595
func Listen(network, address string) (net.Listener, error) {
	if network == "unix" {
		return winio.ListenPipe(address, nil)
	}
	return net.Listen(network, address)
}
725045
func (g *Group) File(path, file string) {
	g.server.File(g.prefix+path, file)
}
436183
func Access(path string, mode int) error {
	return unix.Access(path, uint32(mode))
}
1225796
func NewListenerOn(t ListenTarget) (net.Listener, error) {
	f := os.NewFile(t.Fd, t.Name)
	return net.FileListener(f)
}
89868
func unixSyslog() (net.Conn, error) {
	networks := []string{"unixgram", "unix"}
	logPaths := []string{"/dev/log", "/var/run/syslog"}
	var addr string
	for _, n := range networks {
		for _, p := range logPaths {
			addr = p
			if conn, err := net.Dial(n, addr); err == nil {
				return conn, nil
			}
		}
	}
	return nil, errors.New("Could not connect to local syslog socket")
}
1087803
func Unix(sec int64, nsec int64) Time {
	return Time{time.Unix(sec, nsec)}
}
800997
func main() {
	rand.Seed(time.Now().UnixNano())

	go client_task()
	go client_task()
	go client_task()
	go server_task()

	//  Run for 5 seconds then quit
	time.Sleep(5 * time.Second)
}
23600
func CreateListener(endpoint string) (net.Listener, error) {
	protocol, addr, err := parseEndpointWithFallbackProtocol(endpoint, unixProtocol)
	if err != nil {
		return nil, err
	}
	if protocol != unixProtocol {
		return nil, fmt.Errorf("only support unix socket endpoint")
	}

	// Unlink to cleanup the previous socket file.
	err = unix.Unlink(addr)
	if err != nil && !os.IsNotExist(err) {
		return nil, fmt.Errorf("failed to unlink socket file %q: %v", addr, err)
	}

	return net.Listen(protocol, addr)
}
927284
func (h *Handler) ServeUnix(systemGroup, addr string) error {
	return h.listenAndServe("unix", addr, systemGroup)
}
479506
func (s *Server) Listen() {
	// Should only ever be called once
	if !s.listening {
		s.listening = true
		go s.receive()
		go s.processStorage()
		go s.processDrainage()
		log.Println("syslogish server running")
	}
}
531571
func NewSocket(address string) (*net.UnixListener, error) {
	if len(address) > 106 {
		return nil, errors.Errorf("%q: unix socket path too long (> 106)", address)
	}
	l, err := net.Listen("unix", "\x00"+address)
	if err != nil {
		return nil, errors.Wrapf(err, "failed to listen to abstract unix socket %q", address)
	}
	return l.(*net.UnixListener), nil
}