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 authored Aug 23, 2024
1 parent 7d375ec commit 6ba2e03
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions daemon/sdnotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,28 @@ 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] != '/' {
return false, nil
}


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

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (debian:bullseye)

invalid character '"' in octal escape

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (debian:bullseye)

syntax error: unexpected ++ at end of statement

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:20.04)

invalid character '"' in octal escape

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:20.04)

syntax error: unexpected ++ at end of statement

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:22.04)

invalid character '"' in octal escape

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Distro test (ubuntu:22.04)

syntax error: unexpected ++ at end of statement

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build on minimum supported toolchain

illegal character U+0022 '"' in escape sequence

Check failure on line 73 in daemon/sdnotify.go

View workflow job for this annotation

GitHub Actions / Build (1.20.x)

illegal character U+0022 '"' in escape sequence
}

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

if unsetEnvironment {
Expand Down

0 comments on commit 6ba2e03

Please sign in to comment.