Hide Forgot
+++ This bug was initially created as a clone of Bug #573844 +++ Created attachment 400305 [details] Ignore pids where the path of the running program does not match the known path of the service Description of problem: As allowed (but not required) by the LSB, Red Hat implements additional non-pidfile-based methods for determining if a service is running, using pidof. When calling pidof, the current implementation takes the precautions of telling pidof to omit the current pid, and the parent of the current pid. This is presumably to prevent a false positive where the name of the initscript matches the name of the daemon. However, I'm running into a case where this is insufficient. My initscript's stop routine is as follows: stop) pid=$(pidofproc $DAEMON) if [ -z "$pid" ]; then log_success_msg "myservice not running" exit 0 fi killproc $DAEMON -SIGTERM printf "Waiting for myservice[$pid] to terminate" while [ -d "/proc/$pid/" ]; do printf "." sleep 1 echo $pid done printf "\n" rm -f "$PIDFILE" log_success_msg "$DESCRIPTION Terminated" ;; When "pidofproc" runs, the following processes are running: root 11780 10247 0 15:00 pts/0 00:00:00 /bin/sh /etc/init.d/myservice stop root 11781 11780 0 15:00 pts/0 00:00:00 /bin/sh /etc/init.d/myservice stop root 11782 11781 0 15:00 pts/0 00:00:00 /bin/bash /etc/redhat-lsb/lsb_pidofproc /opt/hp/my-service As you can see, the PID & PPID checks are not sufficient, because lsb_pidofproc is adding an additional process in the chain. Version-Release number of selected component (if applicable): redhat-lsb-3.1-12.3.EL initscripts-8.45.30-2.el5 How reproducible: Always. Steps to Reproduce: 1. Create an initscript /etc/init.d/foo for a daemon named foo 2. Make it source /lib/lsb/functions 3. Use the above shutdown code (with s/myservice/foo/ and DAEMON=/path/to/foo) 4. Call stop Actual results: /etc/init.d/foo stop will think the pid of /etc/init.d/foo is a running daemon and attempt to stop it Expected results: /etc/init.d/foo would know /etc/init.d/foo is not the running daemon and not attempt to kill it Additional info: I'll attach a suggested fix, implemented in the initscripts layer. --- Additional comment from Ondrej Vasik on 2012-12-04 15:28:03 CET --- Adding initscripts maintainer to CC, Lukas, please reassign it to initscripts, if you think this change is reasonable. --- Additional comment from Lukáš Nykrýn on 2012-12-05 13:41:47 CET --- Created attachment 658166 [details] add -m option We have fixed this in fedora, in newer version of pidof by parameter -m: When used with -o, will also omit any processes that have the same argv[0] and argv[1] as any explicitly omitted process ids. This can be used to avoid multiple shell scripts concurrently calling pidof returning each other's pids. And then it would be sufficient to just use this in pidofproc. --- a/rc.d/init.d/functions +++ b/rc.d/init.d/functions @@ -204,8 +204,8 @@ __pids_var_run() { # Output PIDs of matching processes, found using pidof __pids_pidof() { - pidof -c -o $$ -o $PPID -o %PPID -x "$1" || \ - pidof -c -o $$ -o $PPID -o %PPID -x "${1##*/}" + pidof -c -m -o $$ -o $PPID -o %PPID -x "$1" || \ + pidof -c -m -o $$ -o $PPID -o %PPID -x "${1##*/}" } This patch probably needs some minor modification to be applicable for rhel. I don't think it is worth of backporting for rhel5, but we should consider it for rhel6.
https://git.fedorahosted.org/cgit/initscripts.git/commit/?h=rhel6-branch&id=31cb38acfa4cdbfaa65a81cf0c95a3675eeefc27
======================================== Verified in version: sysvinit-tools-2.87-6.dsf.el6.x86_64 initscripts-9.03.40-2.el6.x86_64 PASSED ======================================== # cp /bin/sleep . # sleep 3600 & [1] 9264 # sleep 3600 & [2] 9265 # ./sleep 3600 & [3] 9266 # ./sleep 3600 & [4] 9267 # pidof sleep 9267 9266 9265 9264 # pidof sleep -o 9265 9267 9266 9264 # pidof sleep 9267 9266 9265 9264 # pidof sleep -o 9265 -m 9267 9266 # ======================================== Reproduced in version: sysvinit-tools-2.87-4.dsf.el6.x86_64 initscripts-9.03.31-2.el6.x86_64 FAIL ======================================== # cp /bin/sleep . # sleep 3600 & [1] 6998 # sleep 3600 & [2] 6999 # ./sleep 3600 & [3] 7000 # ./sleep 3600 & [4] 7001 # pidof sleep 7001 7000 6999 6998 # pidof sleep -o 6999 7001 7000 6998 # pidof sleep -o 6999 -m pidof: invalid options on command line! #
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://rhn.redhat.com/errata/RHBA-2015-1380.html