~juju-qa/ubuntu/yakkety/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/github.com/coreos/go-systemd/daemon/sdnotify.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 17:28:37 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202172837-jkrbdlyjcxtrii2n
Initial commit of 1.25.6

Show diffs side-by-side

added added

removed removed

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