[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#668416: killproc incorrect exit status



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
From 5cafecc339c585699b064a5c57149f6d367d7c8b Mon Sep 17 00:00:00 2001
From: Didier Raboud <odyx@debian.org>
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 <petere@debian.org>
Signed-off-by: Didier Raboud <odyx@debian.org>
---
 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

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: