diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-12 12:57:26 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-09-12 12:57:26 -0600 |
commit | 0f1621dc0ebb0e97cfeb9c7c5585ee8b545228ba (patch) | |
tree | 1806d0099da8f1968712a0d4f6edef8bc46a1402 /src/nslcd_systemd | |
parent | ff571cf730cad687d5cfda4db719e16f3fb4c801 (diff) |
nslcd_systemd: clean up
Diffstat (limited to 'src/nslcd_systemd')
-rw-r--r-- | src/nslcd_systemd/nslcd_systemd.go | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/nslcd_systemd/nslcd_systemd.go b/src/nslcd_systemd/nslcd_systemd.go index be465bb..f592279 100644 --- a/src/nslcd_systemd/nslcd_systemd.go +++ b/src/nslcd_systemd/nslcd_systemd.go @@ -65,12 +65,6 @@ func handler(conn *net.UnixConn, backend nslcd_proto.Backend) { func Main(backend Backend) uint8 { var err error = nil - var socket net.Listener = nil - defer func() { - if socket != nil { - socket.Close() - } - }() sigs := make(chan os.Signal) signal.Notify(sigs, syscall.SIGTERM, syscall.SIGHUP) @@ -85,42 +79,44 @@ func Main(backend Backend) uint8 { } defer backend.Close() - socket, err = get_socket() + socket, err := get_socket() if err != nil { logger.Err("%v", err) sd.Notify(false, "STOPPING=1") return lsb.EXIT_NOTRUNNING } + defer socket.Close() sock := make(chan *net.UnixConn) go func() { defer lsb.Recover() for { conn, err := socket.Accept() if err != nil { - logger.Notice("Could not accept connection: %v", err) + logger.Notice("%v", err) + } + if conn != nil { + sock <- conn.(*net.UnixConn) } - sock <- conn.(*net.UnixConn) } }() - exit := lsb.EXIT_SUCCESS var wg sync.WaitGroup + defer wg.Wait() + defer sd.Notify(false, "STOPPING=1") sd.Notify(false, "READY=1") -Loop: for { select { case sig := <-sigs: switch sig { case syscall.SIGTERM: logger.Notice("Received SIGTERM, shutting down") - break Loop + return lsb.EXIT_SUCCESS case syscall.SIGHUP: sd.Notify(false, "RELOADING=1") err := backend.Reload() if err != nil { logger.Notice("Could not reload backend: %s", err.Error()) - exit = lsb.EXIT_NOTRUNNING - break Loop + return lsb.EXIT_NOTRUNNING } sd.Notify(false, "READY=1") } @@ -133,8 +129,5 @@ Loop: }() } } - sd.Notify(false, "STOPPING=1") - wg.Wait() - - return exit + panic("not reached") } |