From 321e6c8958823f64fa2464497f9d217712f93530 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 17 Dec 2016 21:32:34 -0500 Subject: Adjust to the new libsystemd.git/sd_daemon interface. --- systemd/disable_nss_module.go | 16 +++++++++------- systemd/nslcd_systemd.go | 40 ++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/systemd/disable_nss_module.go b/systemd/disable_nss_module.go index da86582..9a8b388 100644 --- a/systemd/disable_nss_module.go +++ b/systemd/disable_nss_module.go @@ -1,6 +1,6 @@ // Copyright (C) 2006 West Consulting // Copyright (C) 2006-2015 Arthur de Jong -// Copyright (C) 2015 Luke Shumaker +// Copyright (C) 2015-2016 Luke Shumaker // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -20,8 +20,10 @@ package nslcd_systemd import ( + "fmt" + "lukeshu.com/git/go/libgnulinux.git/dl" - "lukeshu.com/git/go/libsystemd.git/sd_daemon/logger" + sd "lukeshu.com/git/go/libsystemd.git/sd_daemon" ) //static char *strary(char **ary, unsigned int n) { return ary[n]; } @@ -38,22 +40,22 @@ func disable_nss_module() { if err == nil { defer handle.Close() } else { - logger.Warning("NSS module %s not loaded: %v", nss_module_soname, err) + sd.Log.Warning(fmt.Sprintf("NSS module %s not loaded: %v", nss_module_soname, err)) return } c_version_info, err := handle.Sym(nss_module_sym_version) if err == nil { g_version_info := (**C.char)(c_version_info) - logger.Debug("NSS module %s version %s %s", nss_module_soname, + sd.Log.Debug(fmt.Sprintf("NSS module %s version %s %s", nss_module_soname, C.GoString(C.strary(g_version_info, 0)), - C.GoString(C.strary(g_version_info, 1))) + C.GoString(C.strary(g_version_info, 1)))) } else { - logger.Warning("NSS module %s version missing: %v", nss_module_soname, err) + sd.Log.Warning(fmt.Sprintf("NSS module %s version missing: %v", nss_module_soname, err)) } c_enable_flag, err := handle.Sym(nss_module_sym_enablelookups) if err != nil { - logger.Warning("Unable to disable NSS ldap module for nslcd process: %v", err) + sd.Log.Warning(fmt.Sprintf("Unable to disable NSS ldap module for nslcd process: %v", err)) return } g_enable_flag := (*C.int)(c_enable_flag) diff --git a/systemd/nslcd_systemd.go b/systemd/nslcd_systemd.go index 106323c..c5c8c65 100644 --- a/systemd/nslcd_systemd.go +++ b/systemd/nslcd_systemd.go @@ -1,4 +1,4 @@ -// Copyright (C) 2015 Luke Shumaker +// Copyright (C) 2015-2016 Luke Shumaker // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -34,15 +34,15 @@ package nslcd_systemd import ( "fmt" - "lukeshu.com/git/go/libnslcd.git/proto/server" - "lukeshu.com/git/go/libsystemd.git/sd_daemon" - "lukeshu.com/git/go/libsystemd.git/sd_daemon/logger" - "lukeshu.com/git/go/libsystemd.git/sd_daemon/lsb" "net" "os" "os/signal" "sync" "syscall" + + "lukeshu.com/git/go/libnslcd.git/proto/server" + sd "lukeshu.com/git/go/libsystemd.git/sd_daemon" + "lukeshu.com/git/go/libsystemd.git/sd_daemon/lsb" ) type Backend interface { @@ -84,14 +84,14 @@ func handler(conn *net.UnixConn, backend nslcd_server.Backend) { defer conn.Close() cred, err := getpeercred(conn) if err != nil { - logger.Debug("Connection from unknown client") + sd.Log.Debug("Connection from unknown client") } else { - logger.Debug("Connection from pid=%v uid=%v gid=%v", - cred.Pid, cred.Uid, cred.Gid) + sd.Log.Debug(fmt.Sprintf("Connection from pid=%v uid=%v gid=%v", + cred.Pid, cred.Uid, cred.Gid)) } err = nslcd_server.HandleRequest(backend, conn, conn, cred) if err != nil { - logger.Notice("Error while handling request: %v", err) + sd.Log.Notice(fmt.Sprintf("Error while handling request: %v", err)) } } @@ -105,16 +105,16 @@ func Main(backend Backend) uint8 { err = backend.Init() if err != nil { - logger.Err("Could not initialize backend: %v", err) - sd.Notify(false, "STOPPING=1") + sd.Log.Err(fmt.Sprintf("Could not initialize backend: %v", err)) + sd.Notify(0, false, "STOPPING=1", nil) return lsb.EXIT_FAILURE } defer backend.Close() socket, err := get_socket() if err != nil { - logger.Err("%v", err) - sd.Notify(false, "STOPPING=1") + sd.Log.Err(fmt.Sprintf("%v", err)) + sd.Notify(0, false, "STOPPING=1", nil) return lsb.EXIT_NOTRUNNING } defer socket.Close() @@ -124,7 +124,7 @@ func Main(backend Backend) uint8 { for { conn, err := socket.Accept() if err != nil { - logger.Notice("%v", err) + sd.Log.Notice(fmt.Sprintf("%v", err)) } if conn != nil { sock <- conn.(*net.UnixConn) @@ -134,23 +134,23 @@ func Main(backend Backend) uint8 { var wg sync.WaitGroup defer wg.Wait() - defer sd.Notify(false, "STOPPING=1") - sd.Notify(false, "READY=1") + defer sd.Notify(0, false, "STOPPING=1", nil) + sd.Notify(0, false, "READY=1", nil) for { select { case sig := <-sigs: switch sig { case syscall.SIGTERM: - logger.Notice("Received SIGTERM, shutting down") + sd.Log.Notice("Received SIGTERM, shutting down") return lsb.EXIT_SUCCESS case syscall.SIGHUP: - sd.Notify(false, "RELOADING=1") + sd.Notify(0, false, "RELOADING=1", nil) err := backend.Reload() if err != nil { - logger.Notice("Could not reload backend: %s", err.Error()) + sd.Log.Notice(fmt.Sprintf("Could not reload backend: %s", err.Error())) return lsb.EXIT_NOTRUNNING } - sd.Notify(false, "READY=1") + sd.Notify(0, false, "READY=1", nil) } case conn := <-sock: wg.Add(1) -- cgit v1.2.3-2-g168b