cmd: UNIX sockets: try to autoremove stale sockets

This commit is contained in:
Christian Schwarz 2017-09-18 00:16:10 +02:00
parent eaed271a00
commit 458c28e1d0

View File

@ -22,5 +22,14 @@ func ListenUnixPrivate(sockaddr *net.UnixAddr) (*net.UnixListener, error) {
return nil, errors.Errorf("%s must not be world-accessible (permissions are %#o)", p)
}
// Maybe things have not been cleaned up before
s, err := os.Stat(sockaddr.Name)
if err == nil {
if s.Mode()&os.ModeSocket != 0 {
// opportunistically try to remove it, but if this fails, it is not an error
os.Remove(sockaddr.Name)
}
}
return net.ListenUnix("unix", sockaddr)
}