Bug#668958: lsb-base: pidofproc doesn't return correct status for daemons without pidfile

"Didier 'OdyX' Raboud" <[email protected]>
Newsgroups gmane.linux.debian.devel.lsb
Organization Debian, the Universal OS
Message-ID <4F8BD6FD.5050401__38476.0031513453$1334564845$gmane$org@debian.org>
tags 668958 +patch
thanks

Le 16.04.2012 03:48, Adrian Fita a écrit :
> Hi.
> 
> I noticed that "/etc/init.d/hddtemp status" wasn't returning the correct
> status when the daemon was running. hddtemp daemon doesn't create a pidfile
> when started, so I tracked the problem back to the pidofproc function
> from /lib/lsb/init-functions.

Hi Adrian, and thanks for your bugreport,

as far as I can see, this behaviour has been broken by my fix for #664621:

http://anonscm.debian.org/gitweb/?p=collab-maint/lsb.git;a=commitdiff;h=23c14db

> Basically I put the section with "if [ -x /bin/pidof ] && [ !
> "$specified" ]; then" before the section with "base=${1##*/}". Now the
> function is corectly detecting the pids and "/etc/init.d/hddtemp status"
> gives the right information. Please check the attached patch. I also
> tested the other daemons on my system, both with pidfiles and without
> and all seem to work fine.

This patch (besides being reversed) makes all "pidofproc with
unspecified pidfile name" calls call /bin/pidof, which is undesired IMHO.

I propose the attached patch, that only resorts to calling /bin/pidof
when the pidfile is provably inexistant and when it wasn't specified at
first.

Can you please test it and report back?

Cheers, OdyX
0001-pidofproc-Make-sure-to-try-bin-pidof-when-no-pidfile.patch (text/x-diff, 1.5 KB)
From 05b2f8781d80ede77c817c963583d674b3ae1502 Mon Sep 17 00:00:00 2001
From: Didier Raboud <[email protected]>
Date: Mon, 16 Apr 2012 10:09:09 +0200
Subject: [PATCH] pidofproc(): Make sure to try /bin/pidof when no pidfile is specified.

Closes: #668958
Reported-by: Adrian Fita <[email protected]>
Signed-off-by: Didier Raboud <[email protected]>
---
 init-functions |   19 ++++++++++---------
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/init-functions b/init-functions
index 3be5648..512f1bf 100644
--- a/init-functions
+++ b/init-functions
@@ -100,17 +100,18 @@ pidofproc () {
         return 4 # pid file not readable, hence status is unknown.
       fi
      else
-       return 3 # pid file doesn't exist, program probably stopped
+       # pid file doesn't exist, try to find the pid nevertheless
+       if [ -x /bin/pidof ] && [ ! "$specified" ]; then
+         status="0"
+         /bin/pidof -o %PPID -x $1 || status="$?"
+         if [ "$status" = 1 ]; then
+             return 3 # program is not running
+         fi
+         return 0
+       fi
+       return 3 # specified pid file doesn't exist, program probably stopped
      fi
     fi
-    if [ -x /bin/pidof ] && [ ! "$specified" ]; then
-        status="0"
-        /bin/pidof -o %PPID -x $1 || status="$?"
-        if [ "$status" = 1 ]; then
-            return 3 # program is not running
-        fi
-        return 0
-    fi
     if [ "$specified" ]; then
         return 3 # almost certain it's not running
     fi
-- 
1.7.2.5
signature.asc (application/pgp-signature, 663 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)

iQGcBAEBAgAGBQJPi9b+AAoJEIvPpx7KFjRV5g8L/3V4SiMSEFR/NAtvoYe02J3Z
iC+jMZip4pPdbTPhzuw/i7BN71NlZYp0gyTmxLG3ifp41dIw+U26p4q1pot9LkdJ
vjd3rx1SxkAvBkw1hsiDJb9xkUX/6vZFQpfyjZjKAso3pFPUrPLGs9qAgw7d8d/E
HY1EOv3cRWGK78f8sudMbv7nGs3pgLUwioxN1wFRTDMd/SEQX4iDp+kcE88XN7CR
5VbAwHL8/eZ9Itu0Z9o4h3r2gpS+YHAfjTFGjPFTx0CeDJ11oWVq6Mfgog4FU1Ta
sAUrFqczBTIrLhJLiUso4Q5Escddzqal8orVqoOG52qM0kXl5WU92/aJ8e1cH+Sh
tSjMWMWyvgXA7KvTWOXTAMotAXbxCdJHckgxpk2yBgKxDZn09frynUtpfpkPDy1l
0C2edMet1ttRdmMsR9/E20zNSSan3PL5pWwI7pQWhM0P00Gdw1bjIAH4Wvp3ltGh
n963Hb8sX3OM/GwAFV4+cuzyyDsb5nzMSO2X10iUGQ==
=y8et
-----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.