Skip to content

Commit

Permalink
daemon: SdNotify: add support for abstract unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
arianvp committed Aug 23, 2024
1 parent 7d375ec commit b38a3a1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions daemon/sdnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,29 @@ const (
// (false, err) - notification supported, but failure happened (e.g. error connecting to NOTIFY_SOCKET or while sending data)
// (true, nil) - notification supported, data has been sent
func SdNotify(unsetEnvironment bool, state string) (bool, error) {
socketAddr := &net.UnixAddr{
Name: os.Getenv("NOTIFY_SOCKET"),
Net: "unixgram",
}
notifySocket := os.Getenv("NOTIFY_SOCKET")

// NOTIFY_SOCKET not set
if socketAddr.Name == "" {
if notifySocket == "" {
return false, nil
}

// socket type not supported. We only support unix domain sockets
// but NOTIFY_SOCKET can also use vsock
if notifySocket[0] != '@' || notifySocket[0] != '/' {

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (debian:bullseye)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build on minimum supported toolchain

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:20.04)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build (1.17.x)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:22.04)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build (1.18.x)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build (1.19.x)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'

Check failure on line 66 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x)

suspect or: notifySocket[0] != '@' || notifySocket[0] != '/'
return false, nil
}

// abstract unix socket. Start with a 0-byte
if notifySocket[0] == '@' {
notifySocket = "\x00" + notifySocket[1:]
}

socketAddr := &net.UnixAddr{
Name: notifySocket,
Net: "unixgram",
}

if unsetEnvironment {
if err := os.Unsetenv("NOTIFY_SOCKET"); err != nil {
return false, err
Expand Down

0 comments on commit b38a3a1

Please sign in to comment.