Bug#668416: killproc incorrect exit status

"Didier 'OdyX' Raboud" <[email protected]>
Newsgroups gmane.linux.debian.devel.lsb
Organization Debian, the Universal OS
Message-ID <[email protected]>
severity 668416 serious
tags 668416 +patch
thanks

Le 11.04.2012 19:59, Peter Eisentraut a écrit :
> Somewhere between versions 3.2+Debian31 and 4.1+Debian0, the exit
> status of the killproc function (/lib/lsb/init-functions) was changed
> to return 3 when the program is not running.  This is only correct
> when a signal was specified; see
> <http://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html>:
> 
>     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.
> 
> This breaks init scripts that rely on this behavior; see for example
> bug #667623.

Hi Peter, and thanks for your bugreport. This seems serious enough to
warrant RC severity IMHO, hence hereby rising severity.

> Simple test:
> 
>     sudo bash
>     . /lib/lsb/init-functions
>     killproc /usr/bin/nonexistent
>     echo $?
> 
> should print 0.  It now prints 3.

Attached is a proposed patch: as far as I can see, it does solve the
problem pointed by this bugreport and does indeed work in the testcase
you propose, but I'm not confident enough to claim it doesn't break
anything else; would you mind to take a look?

Cheers,

OdyX
0001-In-killproc-make-sure-to-exit-0-when-the-program-is-.patch (text/x-diff, 1.8 KB)
From 5cafecc339c585699b064a5c57149f6d367d7c8b Mon Sep 17 00:00:00 2001
From: Didier Raboud <[email protected]>
Date: Thu, 12 Apr 2012 14:13:35 +0200
Subject: [PATCH] In killproc(), make sure to exit 0 when the program is not running and when no signal was specified.

Closes: #668416
Reported-by: Peter Eisentraut <[email protected]>
Signed-off-by: Didier Raboud <[email protected]>
---
 init-functions |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/init-functions b/init-functions
index 3be5648..9aa1db7 100644
--- a/init-functions
+++ b/init-functions
@@ -142,41 +142,41 @@ killproc () {
     sig=$(echo ${2:-} | sed -e 's/^-\(.*\)/\1/')
     sig=$(echo $sig | sed -e 's/^SIG\(.*\)/\1/')
     if [ "$sig" = 15 ] || [ "$sig" = TERM ]; then
         is_term_sig="terminate_signal"
     fi
     status=0
     if [ ! "$is_term_sig" ]; then
         if [ -n "$sig" ]; then
             /sbin/start-stop-daemon --stop --signal "$sig" \
 		--quiet $name_param || status="$?"
         else
             /sbin/start-stop-daemon --stop \
 		--retry 5 \
 		--quiet $name_param || status="$?"
         fi
     else
         /sbin/start-stop-daemon --stop --quiet \
 	    --oknodo $name_param || status="$?"
     fi
     if [ "$status" = 1 ]; then
-        if [ -n "$sig" ]; then
+        if [ -z "$sig" ]; then
             return 0
         fi
         return 3 # program is not running
     fi
 
     if [ "$status" = 0 ] && [ "$is_term_sig" ] && [ "$pidfile" ]; then
         pidofproc -p "$pidfile" "$1" >/dev/null || rm -f "$pidfile"
     fi
     return 0
 }
 
 # Return LSB status
 status_of_proc () {
     local pidfile daemon name status
 
     pidfile=
     OPTIND=1
     while getopts p: opt ; do
         case "$opt" in
             p)  pidfile="$OPTARG";;
-- 
1.7.2.5
signature.asc (application/pgp-signature, 663 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQGcBAEBAgAGBQJPhsjXAAoJEIvPpx7KFjRVy4kL/ilUcTB1byLFD9rAl9GE8iPP
1PDEVGDwqb12AzffIITAkqXGkJXci1W3LKY282uYI2++U3cUognut0Unz0u6/QzT
TC2ssd1Ez3gKu7C0KVGKDLcUzF8odHPmwUxjj1w7rGluHuE0wYHnXDueaJ6VDdoM
plofXMxSBBKcmZEqE+aQoxEmjGzHAmABEK1C/lBXcG0Zi6reFj7W39kVFlmqjiBQ
E/io0QK9BLPD1S/lh4Yg1WmXMmUdx2ccoFabdrCa1wEBUbXV5baYMH0WNDAOMJGA
Q5P90HG3G0tRWAhZBfH6FqduKkagk2Z6QPZfQRRV2EzRwuLxJhQCEWmR6Ao24vPQ
+l1PpzBCKpvQP0LOctp/sENQ4bCYErsBNxDdExrKHWGkqEVdV5ilFMnQmSFcCAGx
iaRvFzhggbZYJbtMUFYhKm9oYubI/s/ZwLOUpIpGGZKO5naaxu7bycFhlFfgCSVt
c2zX3vHJjgtTrLP6HXhOGaC479BRWGtDKt5rBc5tvA==
=PXbv
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.