Bug 1556 - Logic error in the pidofproc subroutine in /etc/rc.d/init.d/functions
Logic error in the pidofproc subroutine in /etc/rc.d/init.d/functions
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: initscripts (Show other bugs)
6.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Cristian Gafton
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 1999-03-16 22:53 EST by Mike McHenry
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 1999-03-17 11:44:06 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Mike McHenry 1999-03-16 22:53:35 EST
I apologize in advance for the length of this report.
Please feel free to email me at mmchen@minn.net if any of
this does not seem clear.

This bug regards the subroutine called 'pidofproc' in the
file /etc/rc.d/init.d/functions. This subroutine is
responsible for determining the pid of a process for the
init.d start/stop scripts if all else fails. Under certain
circumstances this script will not work as it should.

Take a look at this line from /etc/rc.d/init.d/functions,
specifically the last check in pidofproc:

 # Finally try to extract it from ps
   ps auxw | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
     { if ((prog == $11) || (("(" prog ")") == $11) ||
          ((prog ":") == $11)) { print $2 ; exit 0 } }' $1

Now take a look at a "typical" ps auxw (shortened up)

root       515  0.4  0.0   720   216  ?  S   Feb 28  38:31
update (bdflush)
root      1563  0.0  0.1   856   472  ?  S    04:02   0:00
CROND
root      1718  0.0  0.4  1552  1044  ?  S    04:02
0:00 /usr/sbin/sendmail -FCronDaemon -odi -oem -or0s root
root      1732  2.8  0.3  1644   900  ?  S    04:02  29:49
perl /etc/mail/popauth.pl

Basically the pidofproc routine looks in the 11th column
for a "running program" and considers anything surrounded
by spaces a column. As you can see running 'pidofproc
update' will NOT return 515 as it should because of the
extra space introduced by "Feb 28". Hopefully this is
making some sense :) Another case which might cause
problems is shown in the last line but I won't go into that
one as most people are probably not running scripts out of
init.d.

Granted most daemons/init programs should have a PID
associated with them in /var/run and if they do the problem
with pidofproc will never become an issue. There are alot
of possibilities for things to slip through the cracks
though.

I would suggest modifying the line from pidofproc as
follows:

 # Finally try to extract it from ps
  ps ax | awk 'BEGIN { prog=ARGV[1]; ARGC=1 }
       { if ((prog == $5) || (("(" prog ")") == $5) ||
            ((prog ":") == $5)) { print $1 ; exit 0 } }' $1
Comment 1 Bill Nottingham 1999-03-17 11:44:59 EST
fixed in a later initscripts (probably around 3.94 or so.)

Note You need to log in before you can comment on or make changes to this bug.