1
0
mirror of https://github.com/golang/go synced 2024-09-30 12:18:33 -06:00

net: do not unlink unix socket in UnixListener created from fd

Fixes #11826.

Change-Id: Id220dd558ca8d8d78c01975087122d27757deea0
Reviewed-on: https://go-review.googlesource.com/17458
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Russ Cox 2015-12-05 01:15:26 -05:00
parent f939ee13ae
commit a4fd325c17
2 changed files with 6 additions and 5 deletions

View File

@ -91,7 +91,7 @@ func fileListener(f *os.File) (Listener, error) {
case *TCPAddr: case *TCPAddr:
return &TCPListener{fd}, nil return &TCPListener{fd}, nil
case *UnixAddr: case *UnixAddr:
return &UnixListener{fd, laddr.Name}, nil return &UnixListener{fd: fd, path: laddr.Name, unlink: false}, nil
} }
fd.Close() fd.Close()
return nil, syscall.EINVAL return nil, syscall.EINVAL

View File

@ -275,6 +275,7 @@ func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn
type UnixListener struct { type UnixListener struct {
fd *netFD fd *netFD
path string path string
unlink bool
} }
// ListenUnix announces on the Unix domain socket laddr and returns a // 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 { if err != nil {
return nil, &OpError{Op: "listen", Net: net, Source: nil, Addr: laddr.opAddr(), Err: err} 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 // 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 // is at least compatible with the auto-remove
// sequence in ListenUnix. It's only non-Go // sequence in ListenUnix. It's only non-Go
// programs that can mess us up. // programs that can mess us up.
if l.path[0] != '@' { if l.path[0] != '@' && l.unlink {
syscall.Unlink(l.path) syscall.Unlink(l.path)
} }
err := l.fd.Close() err := l.fd.Close()