summaryrefslogtreecommitdiff
path: root/nslcd_systemd
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-09-05 15:27:52 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-09-08 16:55:55 -0400
commit641ef9d6c7f1abf2ec824dc771fa474bd38f429d (patch)
tree37945aae4c5782de2f6efeb94ea309c0cd572731 /nslcd_systemd
parent05c65fb594db885bc1579874e079519dec98fc8a (diff)
nslcd_systemd: Allow permanent network errors to make us exit
Diffstat (limited to 'nslcd_systemd')
-rw-r--r--nslcd_systemd/nslcd_systemd.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/nslcd_systemd/nslcd_systemd.go b/nslcd_systemd/nslcd_systemd.go
index 2ba9899..a828ac5 100644
--- a/nslcd_systemd/nslcd_systemd.go
+++ b/nslcd_systemd/nslcd_systemd.go
@@ -118,6 +118,9 @@ func Main(backend Backend) uint8 {
}
defer backend.Close()
+ var wg sync.WaitGroup
+ defer wg.Wait()
+
socket, err := get_socket()
if err != nil {
sd_daemon.Log.Err(fmt.Sprintf("%v", err))
@@ -126,12 +129,22 @@ func Main(backend Backend) uint8 {
}
defer socket.Close()
sock := make(chan *net.UnixConn)
+ socket_error := make(chan error)
+ wg.Add(1)
go func() {
defer sd_daemon.Recover()
- for {
+ defer wg.Done()
+
+ last := false
+ for !last {
conn, err := socket.Accept()
if err != nil {
- sd_daemon.Log.Notice(fmt.Sprintf("%v", err))
+ if ne, ok := err.(net.Error); ok && ne.Temporary() {
+ sd_daemon.Log.Notice(fmt.Sprintf("%v", err))
+ } else {
+ socket_error <- err
+ last = true
+ }
}
if conn != nil {
sock <- conn.(*net.UnixConn)
@@ -139,8 +152,6 @@ func Main(backend Backend) uint8 {
}
}()
- var wg sync.WaitGroup
- defer wg.Wait()
defer sd_daemon.Notification{State: "STOPPING=1"}.Send(false)
sd_daemon.Notification{State: "READY=1"}.Send(false)
for {
@@ -160,6 +171,9 @@ func Main(backend Backend) uint8 {
}
sd_daemon.Notification{State: "READY=1"}.Send(false)
}
+ case err = <-socket_error:
+ sd_daemon.Log.Err(fmt.Sprintf("%v", err))
+ return sd_daemon.EXIT_FAILURE
case conn := <-sock:
wg.Add(1)
go func() {