Skip to content

Commit 6ba2e03

Browse files
authored
daemon: SdNotify: add support for abstract unix sockets
As per https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#
1 parent 7d375ec commit 6ba2e03

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

daemon/sdnotify.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,28 @@ const (
5454
// (false, err) - notification supported, but failure happened (e.g. error connecting to NOTIFY_SOCKET or while sending data)
5555
// (true, nil) - notification supported, data has been sent
5656
func SdNotify(unsetEnvironment bool, state string) (bool, error) {
57-
socketAddr := &net.UnixAddr{
58-
Name: os.Getenv("NOTIFY_SOCKET"),
59-
Net: "unixgram",
60-
}
57+
notifySocket := os.Getenv("NOTIFY_SOCKET")
6158

6259
// NOTIFY_SOCKET not set
63-
if socketAddr.Name == "" {
60+
if notifySocket == "" {
6461
return false, nil
62+
}
63+
64+
// socket type not supported. We only support unix domain sockets
65+
// but NOTIFY_SOCKET can also use vsock
66+
if notifySocket[0] != '@' || notifySocket[0] != '/' {
67+
return false, nil
68+
}
69+
70+
71+
// abstract unix socket. Start with a 0-byte
72+
if notifySocket[0] == '@' {
73+
notifySocket = "\00" ++ notifySocket[1:]
74+
}
75+
76+
socketAddr := &net.UnixAddr{
77+
Name: notifySocket,
78+
Net: "unixgram",
6579
}
6680

6781
if unsetEnvironment {

0 commit comments

Comments
 (0)