Skip to content

Commit

Permalink
core: Skip chmod for abstract unix sockets (#5596)
Browse files Browse the repository at this point in the history
because those aren't real paths on the filesystem and thus can't be `chmod`ed
  • Loading branch information
emilylange authored Jun 25, 2023
1 parent 22927e2 commit 119e879
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions listeners.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
var err error
var address string
var unixFileMode fs.FileMode
var isAbtractUnixSocket bool

// split unix socket addr early so lnKey
// is independent of permissions bits
Expand All @@ -160,15 +161,19 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
if err != nil {
return nil, err
}
isAbtractUnixSocket = strings.HasPrefix(address, "@")
} else {
address = na.JoinHostPort(portOffset)
}

// if this is a unix socket, see if we already have it open,
// force socket permissions on it and return early
if socket, err := reuseUnixSocket(na.Network, address); socket != nil || err != nil {
if err := os.Chmod(address, unixFileMode); err != nil {
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
if !isAbtractUnixSocket {
if err := os.Chmod(address, unixFileMode); err != nil {
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
}

}
return socket, err
}
Expand Down Expand Up @@ -211,8 +216,10 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
}

if IsUnixNetwork(na.Network) {
if err := os.Chmod(address, unixFileMode); err != nil {
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
if !isAbtractUnixSocket {
if err := os.Chmod(address, unixFileMode); err != nil {
return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
}
}
}

Expand Down

0 comments on commit 119e879

Please sign in to comment.