9bcb3cba83
- pkg/useragent - pkg/units - pkg/ulimit - pkg/truncindex - pkg/timeoutconn - pkg/term - pkg/tarsum - pkg/tailfile - pkg/systemd - pkg/stringutils - pkg/stringid - pkg/streamformatter - pkg/sockets - pkg/signal - pkg/proxy - pkg/progressreader - pkg/pools - pkg/plugins - pkg/pidfile - pkg/parsers - pkg/parsers/filters - pkg/parsers/kernel - pkg/parsers/operatingsystem Signed-off-by: Vincent Demeester <vincent@sbr.pm>
34 lines
629 B
Go
34 lines
629 B
Go
package systemd
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
"os"
|
|
)
|
|
|
|
// ErrSdNotifyNoSocket is an error returned if no socket was specified.
|
|
var ErrSdNotifyNoSocket = errors.New("No socket")
|
|
|
|
// SdNotify sends a message to the init daemon. It is common to ignore the return value.
|
|
func SdNotify(state string) error {
|
|
socketAddr := &net.UnixAddr{
|
|
Name: os.Getenv("NOTIFY_SOCKET"),
|
|
Net: "unixgram",
|
|
}
|
|
|
|
if socketAddr.Name == "" {
|
|
return ErrSdNotifyNoSocket
|
|
}
|
|
|
|
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = conn.Write([]byte(state))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|