pidofproc(): Make sure to try /bin/pidof when no pidfile is specified.
authorDidier Raboud <odyx@debian.org>
Mon, 16 Apr 2012 08:09:09 +0000 (10:09 +0200)
committerDidier Raboud <odyx@debian.org>
Tue, 17 Apr 2012 09:56:22 +0000 (11:56 +0200)
Move the pidof-using block inside the conditional to have it run when we know
that the pidfile doesn't exist but before assuming that the program was indeed
using one.

Closes: #668958
Reported-by: Adrian Fita <adrian.fita@gmail.com>
Signed-off-by: Didier Raboud <odyx@debian.org>
init-functions

index 3be5648fb3cf9e1fdcd10901f1493035456741f4..512f1bfc2f94c782c08689c2ca1b692d11c50782 100644 (file)
@@ -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