[ale] Strange happenings with pidof command.

Jim Lynch ale_nospam at fayettedigital.com
Sat Jul 26 14:46:03 EDT 2008


This one's got me beat.  I can't see what the problem is, probably 
because I've been staring at it too long.  pidof works in one case and 
doesn't in another.  I can't find the difference.

Here's the details:

So how come root can't use pidof but a normal user can?  Here's a demo 
of what's happening.  Vaprobe and run_xrpc are almost identical 
scripts.  Both start with a #!/bin/bash line, not that pidof would care.

[jim at devel xmlrpcsrv]$ ps -e | grep run
31347 pts/1    00:00:00 run_xrpc
31429 pts/1    00:00:00 vaprobe_run
[jim at devel xmlrpcsrv]$ file /usr/local/bin/vaprobe_run 
/usr/local/bin/run_xrpc
/usr/local/bin/vaprobe_run: Bourne-Again shell script text executable
/usr/local/bin/run_xrpc:    Bourne-Again shell script text executable
[jim at devel xmlrpcsrv]$ ls -lb /usr/local/bin/vaprobe_run 
/usr/local/bin/run_xrpc
-rwxr-xr-x  1 root root 466 Jul 26 13:57 /usr/local/bin/run_xrpc
-rwxr-xr-x  1 root root 448 Jul 26 06:41 /usr/local/bin/vaprobe_run
[jim at devel xmlrpcsrv]$ /sbin/pidof -x /usr/local/bin/run_xrpc
31347
[jim at devel xmlrpcsrv]$ /sbin/pidof -x /usr/local/bin/vaprobe_run
31429
[jim at devel xmlrpcsrv]$ sudo /sbin/pidof -x /usr/local/bin/run_xrpc

[jim at devel xmlrpcsrv]$ sudo /sbin/pidof -x /usr/local/bin/vaprobe_run
31429

Both of these scripts are started from /etc/init.d scripts, here are the 
important lines from each so you can see they were started in a like 
manner.  Both start with a #!/bin/bash.

PROGHOME=/usr/local/bin
LOGHOME=/var/log/

RETVAL=0

prog=xmlrpcsrv
runprog=run_xrpc

runfull=/usr/local/bin/run_xrpc
# Source function library.
. /etc/rc.d/init.d/functions

start ()
{
    cd $PROGHOME
    ulimit -c 50000
    ulimit -n 20
    touch /var/lock/subsys/$prog
    $PROGHOME/$runprog  >/dev/null 2>&1  &
    runfull=$PROGHOME/$runprog
    echo -n $"Starting $prog: "




PROGHOME=/usr/local/bin
LOGHOME=/var/log/


RETVAL=0

prog=vaprobe
aprog=vaprobe_run

# Source function library.
. /etc/rc.d/init.d/functions

start ()
{
    touch /var/lock/subsys/$prog
    vprog=$PROGHOME/$aprog
    $vprog >/dev/null 2>&1 &
    echo -n $"Starting $prog: "

Here's the output of the strace command from both attempts:

(truncated a bunch, or cut off above the knees since this is a tail)

Running as normal user:

lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin/xmlrpcsrv_run", {st_mode=S_IFREG|0755, 
st_size=463, ...}) = 0
fstat64(1, {st_mode=S_IFREG|0644, st_size=63246, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0xb7f9c000
write(1, "23149\n", 623149
)                  = 6
exit_group(0)                           = ?

Running as super user:

lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin/xmlrpcsrv_run", {st_mode=S_IFREG|0755, 
st_size=463, ...}) = 0
lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/usr/local/bin/-x", 0xbf95a598) = -1 ENOENT (No such file or 
directory)
fstat64(1, {st_mode=S_IFREG|0644, st_size=62101, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0xb7ef6000
write(1, "\n", 1
)                       = 1
exit_group(1)                           = ?

In the first case it stopped with an lstat of the file in question, but 
it looks like it didn't like the lstat in the second case and went on to 
try to find a parameter.  Strange....

Strace output from pidof the other file, vaprobe_run give similar 
results as the normal user's output above, as expected.

I know I'm doing something wrong, but what?

Here's a copy of run_xrpc

#!/bin/bash
#
PROGHOME=/usr/local/bin
LOGHOME=/var/log/

RETVAL=0

prog=xmlrpcsrv

# Source function library.
. /etc/rc.d/init.d/functions

    cd $PROGHOME
    ulimit -c 50000
    runfile=/var/lock/subsys/xmlrpcsrv
    while test  -e  $runfile
do
    $PROGHOME/$prog  >> $LOGHOME/xmlrpcsrv.log 2>&1
    sleep 2
    pid=`cat /tmp/xmlrpcsrv.LCK` 2>/dev/null
    checkpid $pid
    if [ $? = 0 ]
    then
        exit
    fi
done

vaprobe_run is identical except for the names.

Thanks for a fresh set of eyes and brains,
Jim.


More information about the Ale mailing list