Skip to content

Commit a4fd325

Browse files
committed
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 <[email protected]>
1 parent f939ee1 commit a4fd325

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/net/file_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func fileListener(f *os.File) (Listener, error) {
9191
case *TCPAddr:
9292
return &TCPListener{fd}, nil
9393
case *UnixAddr:
94-
return &UnixListener{fd, laddr.Name}, nil
94+
return &UnixListener{fd: fd, path: laddr.Name, unlink: false}, nil
9595
}
9696
fd.Close()
9797
return nil, syscall.EINVAL

src/net/unixsock_posix.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,9 @@ func dialUnix(net string, laddr, raddr *UnixAddr, deadline time.Time) (*UnixConn
273273
// typically use variables of type Listener instead of assuming Unix
274274
// domain sockets.
275275
type UnixListener struct {
276-
fd *netFD
277-
path string
276+
fd *netFD
277+
path string
278+
unlink bool
278279
}
279280

280281
// ListenUnix announces on the Unix domain socket laddr and returns a
@@ -292,7 +293,7 @@ func ListenUnix(net string, laddr *UnixAddr) (*UnixListener, error) {
292293
if err != nil {
293294
return nil, &OpError{Op: "listen", Net: net, Source: nil, Addr: laddr.opAddr(), Err: err}
294295
}
295-
return &UnixListener{fd: fd, path: fd.laddr.String()}, nil
296+
return &UnixListener{fd: fd, path: fd.laddr.String(), unlink: true}, nil
296297
}
297298

298299
// AcceptUnix accepts the next incoming call and returns the new
@@ -335,7 +336,7 @@ func (l *UnixListener) Close() error {
335336
// is at least compatible with the auto-remove
336337
// sequence in ListenUnix. It's only non-Go
337338
// programs that can mess us up.
338-
if l.path[0] != '@' {
339+
if l.path[0] != '@' && l.unlink {
339340
syscall.Unlink(l.path)
340341
}
341342
err := l.fd.Close()

0 commit comments

Comments
 (0)