>Synopsis: nsd rc script check returns strange exit code when nsd not
>running.
>Category: system
>Environment:
System : OpenBSD 5.5
Details : OpenBSD 5.5 (GENERIC) #271: Wed Mar 5 09:31:16 MST 2014
[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC
Architecture: OpenBSD.amd64
Machine : amd64
>Description:
The nsd rc script returns an exit code other than 1 when nsd is not
running. A problem arises when using
a configuration management (CM) system such as ansible to control system
services. With this non-standard exit code, the
CM system cannot determine if the service is running or not. The nsd rc script
runs 'nsd-control status', which documentation
states will exit 3 when nsd is not running. I'd argue that the rc script should
catch that, and instead exit 1.
>How-To-Repeat:
Starting with nsd running:
$ ps -aux | grep nsd
_nsd 19396 0.0 12.6 26856 23792 ?? Ss 11:39PM
0:00.03 nsd -c /var/nsd/etc/nsd.conf
_nsd 9466 0.0 17.5 32884 32948 ?? I 11:39PM
0:00.03 nsd -c /var/nsd/etc/nsd.conf
_nsd 14042 0.0 0.7 33100 1276 ?? I 11:39PM
0:00.00 nsd -c /var/nsd/etc/nsd.conf
Check the process status, and exit code
$ sudo /etc/rc.d/nsd check; echo $?
0
Now, stop nsd.
$ sudo /etc/rc.d/nsd stop
nsd(ok)
Again, check the status and exit code.
$ sudo /etc/rc.d/nsd check; echo $?
3
>Fix:
Index: nsd
===================================================================
RCS file: /cvs/src/etc/rc.d/nsd,v
retrieving revision 1.7
diff -u -p -u -r1.7 nsd
--- nsd 7 May 2014 02:46:05 -0000 1.7
+++ nsd 25 Jun 2014 03:53:50 -0000
@ -25,6 +25,12 @@ rc_start() {
rc_check() {
${daemon} ${daemon_flags} status
+ ret=$?
+ if [[ $ret != 0 ]]; then
+ return 1
+ else
+ return 0
+ fi
}
rc_reload() {