sdnotify.go 564 B

1234567891011121314151617181920212223242526272829303132
  1. // Code forked from Docker project
  2. package daemon
  3. import (
  4. "errors"
  5. "net"
  6. "os"
  7. )
  8. var SdNotifyNoSocket = errors.New("No socket")
  9. // SdNotify sends a message to the init daemon. It is common to ignore the error.
  10. func SdNotify(state string) error {
  11. socketAddr := &net.UnixAddr{
  12. Name: os.Getenv("NOTIFY_SOCKET"),
  13. Net: "unixgram",
  14. }
  15. if socketAddr.Name == "" {
  16. return SdNotifyNoSocket
  17. }
  18. conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
  19. if err != nil {
  20. return err
  21. }
  22. defer conn.Close()
  23. _, err = conn.Write([]byte(state))
  24. return err
  25. }