Merge pull request #5746 from lifupan/main

runtime: fix the issue of create new socket with abstract address
This commit is contained in:
Maksym Pavlenko 2021-07-29 15:40:28 -07:00 committed by GitHub
commit fcd9c41991
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,7 +90,10 @@ func NewSocket(address string) (*net.UnixListener, error) {
sock = socket(address)
path = sock.path()
)
if !sock.isAbstract() {
isAbstract := sock.isAbstract()
if !isAbstract {
if err := os.MkdirAll(filepath.Dir(path), 0600); err != nil {
return nil, errors.Wrapf(err, "%s", path)
}
@ -99,10 +102,13 @@ func NewSocket(address string) (*net.UnixListener, error) {
if err != nil {
return nil, err
}
if err := os.Chmod(path, 0600); err != nil {
os.Remove(sock.path())
l.Close()
return nil, err
if !isAbstract {
if err := os.Chmod(path, 0600); err != nil {
os.Remove(sock.path())
l.Close()
return nil, err
}
}
return l.(*net.UnixListener), nil
}