summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 21:32:34 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-18 03:41:05 -0500
commit321e6c8958823f64fa2464497f9d217712f93530 (patch)
treed28ba4c9040fcbe50e4913379f22b92bf2bcb3db
parentf3e7a6ad344047f3c1d99e4bfcc9387b489ecdcc (diff)
Adjust to the new libsystemd.git/sd_daemon interface.
-rw-r--r--systemd/disable_nss_module.go16
-rw-r--r--systemd/nslcd_systemd.go40
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 <lukeshu@sbcglobal.net>
+// Copyright (C) 2015-2016 Luke Shumaker <lukeshu@sbcglobal.net>
//
// 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 <lukeshu@sbcglobal.net>
+// Copyright (C) 2015-2016 Luke Shumaker <lukeshu@sbcglobal.net>
//
// 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)