Skip to content

Commit 1ae4dd7

Browse files
authored
Merge pull request #270 from muesli/daemon-cleanup
daemon: Clean up copyright headers and documentation
2 parents dd33654 + 0b72b28 commit 1ae4dd7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

daemon/sdnotify.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2014 Docker, Inc.
2+
// Copyright 2015-2018 CoreOS, Inc.
23
//
34
// Licensed under the Apache License, Version 2.0 (the "License");
45
// you may not use this file except in compliance with the License.
@@ -13,7 +14,11 @@
1314
// limitations under the License.
1415
//
1516

16-
// Code forked from Docker project
17+
// Package daemon provides a Go implementation of the sd_notify protocol.
18+
// It can be used to inform systemd of service start-up completion, watchdog
19+
// events, and other status changes.
20+
//
21+
// https://www.freedesktop.org/software/systemd/man/sd_notify.html#Description
1722
package daemon
1823

1924
import (
@@ -29,7 +34,7 @@ import (
2934
// (false, nil) - notification not supported (i.e. NOTIFY_SOCKET is unset)
3035
// (false, err) - notification supported, but failure happened (e.g. error connecting to NOTIFY_SOCKET or while sending data)
3136
// (true, nil) - notification supported, data has been sent
32-
func SdNotify(unsetEnvironment bool, state string) (sent bool, err error) {
37+
func SdNotify(unsetEnvironment bool, state string) (bool, error) {
3338
socketAddr := &net.UnixAddr{
3439
Name: os.Getenv("NOTIFY_SOCKET"),
3540
Net: "unixgram",
@@ -41,10 +46,9 @@ func SdNotify(unsetEnvironment bool, state string) (sent bool, err error) {
4146
}
4247

4348
if unsetEnvironment {
44-
err = os.Unsetenv("NOTIFY_SOCKET")
45-
}
46-
if err != nil {
47-
return false, err
49+
if err := os.Unsetenv("NOTIFY_SOCKET"); err != nil {
50+
return false, err
51+
}
4852
}
4953

5054
conn, err := net.DialUnix(socketAddr.Net, nil, socketAddr)
@@ -54,9 +58,7 @@ func SdNotify(unsetEnvironment bool, state string) (sent bool, err error) {
5458
}
5559
defer conn.Close()
5660

57-
_, err = conn.Write([]byte(state))
58-
// Error sending the message
59-
if err != nil {
61+
if _, err = conn.Write([]byte(state)); err != nil {
6062
return false, err
6163
}
6264
return true, nil

0 commit comments

Comments
 (0)