From 641ef9d6c7f1abf2ec824dc771fa474bd38f429d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 5 Sep 2017 15:27:52 -0400 Subject: nslcd_systemd: Allow permanent network errors to make us exit --- nslcd_systemd/nslcd_systemd.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'nslcd_systemd') 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() { -- cgit v1.2.3-2-g168b