rclone/vendor/github.com/okzk/sdnotify/notify_linux.go

24 lines
430 B
Go
Raw Normal View History

2017-11-19 22:03:27 +00:00
package sdnotify
import (
"net"
"os"
)
// SdNotify sends a specified string to the systemd notification socket.
2017-11-19 22:03:27 +00:00
func SdNotify(state string) error {
name := os.Getenv("NOTIFY_SOCKET")
if name == "" {
return ErrSdNotifyNoSocket
2017-11-19 22:03:27 +00:00
}
conn, err := net.DialUnix("unixgram", nil, &net.UnixAddr{Name: name, Net: "unixgram"})
if err != nil {
return err
}
defer conn.Close()
_, err = conn.Write([]byte(state))
return err
}