diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nshd/hackers_git/hackers_watch.go | 3 | ||||
-rw-r--r-- | src/nshd/main.go | 2 | ||||
-rw-r--r-- | src/nslcd_systemd/nslcd_systemd.go | 19 | ||||
-rw-r--r-- | src/sd_daemon/lsb/exit-status.go | 62 |
4 files changed, 78 insertions, 8 deletions
diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go index a878f4c..3d72f94 100644 --- a/src/nshd/hackers_git/hackers_watch.go +++ b/src/nshd/hackers_git/hackers_watch.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "sd_daemon/logger" + "sd_daemon/lsb" ) const ( @@ -128,7 +129,7 @@ func (o *Hackers) worker_handle_passwd(uid int32) { func worker_error(format string, a ...interface{}) { logger.Err(format, a) - os.Exit(255) + os.Exit(int(lsb.EXIT_FAILURE)) } func (o *Hackers) worker() { diff --git a/src/nshd/main.go b/src/nshd/main.go index ac49eaa..ebca1a6 100644 --- a/src/nshd/main.go +++ b/src/nshd/main.go @@ -14,5 +14,5 @@ func main() { backend := hackers_git.NewHackers(config) ret := nslcd_systemd.Main(backend) backend.Close() - os.Exit(ret) + os.Exit(int(ret)) } diff --git a/src/nslcd_systemd/nslcd_systemd.go b/src/nslcd_systemd/nslcd_systemd.go index 3d87310..fec60c3 100644 --- a/src/nslcd_systemd/nslcd_systemd.go +++ b/src/nslcd_systemd/nslcd_systemd.go @@ -8,6 +8,7 @@ import ( "os/signal" sd "sd_daemon" "sd_daemon/logger" + "sd_daemon/lsb" "sync" "syscall" ) @@ -60,7 +61,7 @@ func handler(conn *net.UnixConn, backend nslcd_proto.Backend) { } } -func Main(backend Backend) int { +func Main(backend Backend) uint8 { var err error = nil var socket net.Listener = nil defer func() { @@ -73,7 +74,7 @@ func Main(backend Backend) int { if err != nil { logger.Err("%s", err.Error()) sd.Notify(false, "STOPPING=1") - return 1 + return lsb.EXIT_NOTRUNNING } sigs := make(chan os.Signal, 1) @@ -84,12 +85,13 @@ func Main(backend Backend) int { for { conn, err := socket.Accept() if err != nil { - logger.Notice("%s", err.Error()) + logger.Notice("Accept: %s", err.Error()) } sock <- conn.(*net.UnixConn) } }() + exit := lsb.EXIT_SUCCESS var wg sync.WaitGroup sd.Notify(false, "READY=1") Loop: @@ -98,11 +100,15 @@ Loop: case sig := <-sigs: switch sig { case syscall.SIGTERM: - sd.Notify(false, "STOPPING=1") break Loop case syscall.SIGHUP: sd.Notify(false, "RELOADING=1") - backend.Reload() + err := backend.Reload() + if err != nil { + logger.Notice("Reload: %s", err.Error()) + exit = lsb.EXIT_NOTRUNNING + break Loop + } sd.Notify(false, "READY=1") } case conn := <-sock: @@ -113,7 +119,8 @@ Loop: }() } } + sd.Notify(false, "STOPPING=1") wg.Wait() - return 0 + return exit } diff --git a/src/sd_daemon/lsb/exit-status.go b/src/sd_daemon/lsb/exit-status.go new file mode 100644 index 0000000..ba5b68b --- /dev/null +++ b/src/sd_daemon/lsb/exit-status.go @@ -0,0 +1,62 @@ +package lsb + +/* systemd daemon(7) recommends using the exit codes defined in the + * "LSB recomendations for SysV init scripts"[1]. + * + * [1]: http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html + */ +const ( + EXIT_SUCCESS uint8 = 0 + EXIT_FAILURE uint8 = 1 + EXIT_INVALIDARGUMENT uint8 = 2 + EXIT_NOTIMPLEMENTED uint8 = 3 + EXIT_NOPERMISSION uint8 = 4 + EXIT_NOTINSTALLED uint8 = 5 + EXIT_NOTCONFIGURED uint8 = 6 + EXIT_NOTRUNNING uint8 = 7 + /* 8- 99 are reserved for future LSB use */ + /* 100-149 are reserved for distribution use */ + /* 150-199 are reserved for application use */ + /* 200-254 are reserved for init system use */ + + /* Therefore, the following are taken from systemd's + /* `src/basic/exit-status.h` */ + EXIT_CHDIR uint8 = 200 + EXIT_NICE uint8 = 201 + EXIT_FDS uint8 = 202 + EXIT_EXEC uint8 = 203 + EXIT_MEMORY uint8 = 204 + EXIT_LIMITS uint8 = 205 + EXIT_OOM_ADJUST uint8 = 206 + EXIT_SIGNAL_MASK uint8 = 207 + EXIT_STDIN uint8 = 208 + EXIT_STDOUT uint8 = 209 + EXIT_CHROOT uint8 = 210 + EXIT_IOPRIO uint8 = 211 + EXIT_TIMERSLACK uint8 = 212 + EXIT_SECUREBITS uint8 = 213 + EXIT_SETSCHEDULER uint8 = 214 + EXIT_CPUAFFINITY uint8 = 215 + EXIT_GROUP uint8 = 216 + EXIT_USER uint8 = 217 + EXIT_CAPABILITIES uint8 = 218 + EXIT_CGROUP uint8 = 219 + EXIT_SETSID uint8 = 220 + EXIT_CONFIRM uint8 = 221 + EXIT_STDERR uint8 = 222 + _EXIT_RESERVED uint8 = 223 /* used to be tcpwrap don't reuse! */ + EXIT_PAM uint8 = 224 + EXIT_NETWORK uint8 = 225 + EXIT_NAMESPACE uint8 = 226 + EXIT_NO_NEW_PRIVILEGES uint8 = 227 + EXIT_SECCOMP uint8 = 228 + EXIT_SELINUX_CONTEXT uint8 = 229 + EXIT_PERSONALITY uint8 = 230 + EXIT_APPARMOR_PROFILE uint8 = 231 + EXIT_ADDRESS_FAMILIES uint8 = 232 + EXIT_RUNTIME_DIRECTORY uint8 = 233 + EXIT_MAKE_STARTER uint8 = 234 + EXIT_CHOWN uint8 = 235 + EXIT_BUS_ENDPOINT uint8 = 236 + EXIT_SMACK_PROCESS_LABEL uint8 = 237 +) |