Bug 1556 - Logic error in the pidofproc subroutine in /etc/rc.d/init.d/functions
Summary: Logic error in the pidofproc subroutine in /etc/rc.d/init.d/functions
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: initscripts
Version: 6.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Cristian Gafton
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 1999-03-17 03:53 UTC by Mike McHenry
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 1999-03-17 16:44:06 UTC
Embargoed:


Attachments (Terms of Use)

Description Mike McHenry 1999-03-17 03:53:35 UTC
I apologize in advance for the length of this report.
Please feel free to email me at mmchen 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 16:44:59 UTC
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.