]> Cypherpunks repositories - gostls13.git/commitdiff
net: do not unlink unix socket in UnixListener created from fd
authorRuss Cox <rsc@golang.org>
Sat, 5 Dec 2015 06:15:26 +0000 (01:15 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 11 Dec 2015 04:43:44 +0000 (04:43 +0000)
Fixes #11826.

Change-Id: Id220dd558ca8d8d78c01975087122d27757deea0
Reviewed-on: https://go-review.googlesource.com/17458
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/file_unix.go
src/net/unixsock_posix.go

index 5b24c7d09d1da9099c8bb8aced445e6c7e793325..9e581fcb419ad14b4f773206bf36fc5e1c8f5d10 100644 (file)
@@ -91,7 +91,7 @@ func fileListener(f *os.File) (Listener, error) {
        case *TCPAddr:
                return &TCPListener{fd}, nil
        case *UnixAddr:
-               return &UnixListener{fd, laddr.Name}, nil
+               return &UnixListener{fd: fd, path: laddr.Name, unlink: false}, nil
        }
        fd.Close()
        return nil, syscall.EINVAL
index 351d9b3a39ae6b6e54c4c2ff8ad95c5bc53d95c0..fc44c1a458e43b44dc03f3282662973cc3499046 100644 (file)
@@ -273,8 +273,9 @@ func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn
 // typically use variables of type Listener instead of assuming Unix
 // domain sockets.
 type UnixListener struct {
-       fd   *netFD
-       path string
+       fd     *netFD
+       path   string
+       unlink bool
 }
 
 // ListenUnix announces on the Unix domain socket laddr and returns a
@@ -292,7 +293,7 @@ func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
        if err != nil {
                return nil, &OpError{Op: "listen", Net: net, Source: nil, Addr: laddr.opAddr(), Err: err}
        }
-       return &UnixListener{fd: fd, path: fd.laddr.String()}, nil
+       return &UnixListener{fd: fd, path: fd.laddr.String(), unlink: true}, nil
 }
 
 // AcceptUnix accepts the next incoming call and returns the new
@@ -335,7 +336,7 @@ func (l *UnixListener) Close() error {
        // is at least compatible with the auto-remove
        // sequence in ListenUnix.  It's only non-Go
        // programs that can mess us up.
-       if l.path[0] != '@' {
+       if l.path[0] != '@' && l.unlink {
                syscall.Unlink(l.path)
        }
        err := l.fd.Close()