Suspected error in /lib/lsb/init-functions preventing specified killproc signal

Asked by Darren White

It appears that there is an error in the killproc function, which prevents signals other than SIGTERM from being sent to processes. The killproc function in init-functions should send a specified signal to the process. Normally, it is used to kill a process but it can also send SIGHUP, etc.

This error manifested when calling killproc as specified (From the nagios2 init.d file created by the Ubuntu Nagios2 package):
killproc -p "$THEPIDFILE" "$DAEMON" 1
This command should send signal 1 (SIGHUP) to the Nagios2 daemon. Instead it kills it (Sends SIGTERM)

From the LSB docs for killproc:
killproc [-p pidfile] pathname [signal]
The killproc function shall stop the specified program. The program is found using the algorithm given above. If a signal is specified, using the -signal_name or -signal_number syntaxes as specified by the kill command, the program is sent that signal. Otherwise, a SIGTERM followed by a SIGKILL after an unspecified number of seconds shall be sent. If a program has been terminated, the pidfile should be removed if the terminated process has not already done so. The killproc function shall return the LSB defined exit status codes. If called without a signal, it shall return 0 if the program has been stopped or is not running and not 0 otherwise. If a signal is given, it shall return 0 only if the program is running.

The $sig variable is set in the following code in the killproc function:
    sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')
    sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')
    if [ -n "$sig" -o "$sig" = 15 -o "$sig" = TERM ]; then

While testing the logic, I confirmed that $sig was being set to 1, but $is_term_sig was still set to yes. This is happening because the script tests for any $sig value, and if it is set, $is_term_sig is set to yes.

I was able to get the script to operate as desired by changing line 123 from:
if [ -n "$sig" -o "$sig" = 15 -o "$sig" = TERM ]; then
if [ "$sig" = 15 -o "$sig" = TERM ]; then

I suspect the original intent was to test for UNDEFINED, 15, or TERM. The current script tests for ANYVALUE, 15, TERM.

uname a
Linux wasmonitor 2.6.24-19-server #1 SMP Wed Jun 18 15:18:00 UTC 2008 i686 GNU/Linux

cat lsb-release

Question information

English Edit question
Ubuntu lsb Edit question
No assignee Edit question
Solved by:
Albert Damen
Last query:
Last reply:
Revision history for this message
Best Albert Damen (albrt) said :

You are right, that is a bug.
It is known as bug 228460 and has been fixed for the next release of Ubuntu, Intrepid.
The actual fix is to replace the -n $sig by -z $sig, as calling killproc without a signal specified, must be treated as a TERM signal.

Revision history for this message
Darren White (d-launchpad-darrenwhite-org) said :

Thank you for the response, I've modified my function as recommended.