pidofproc falls back to pidof when there is no PID file, like on system
startup.
In my case, this leads to statd not being able to register with the
portmapper and my NFS mounts failing.
Hm, is this the /lib/lsb/init-functions implementation of pidofproc?
It seem to be completely useless if it behave as described here.
I tested this in etch and unstable. It do not work this way in etch:
% cat x
#!/bin/sh
. /lib/lsb/init-functions
pid=`pidofproc x`
echo $pid
% PATH=.:$PATH x
%
While in unstabe, the same script return a pid:
% PATH=.:$PATH x
18769
%
I would say this is a bug in lsb-base. Version 3.1-23.2etch1 work,
while 3.2-20 do not.
This is the working version:
pidofproc () {
local pidfile line i pids= status specified pid
pidfile=
specified=
OPTIND=1
while getopts p: opt ; do
case "$opt" in
p) pidfile="$OPTARG"; specified=1;;
esac
done
shift $(($OPTIND - 1))
if [ -z "${pidfile:-}" ]; then
pidfile=/var/run/${1##*/}.pid
fi
if [ -f "$pidfile" ]; then
read pid < "$pidfile"
if [ -n "${pid:-}" ]; then
if $(kill -0 "${pid:-}" 2> /dev/null); then
echo "$pid"
return 0
else
return 1 # program is dead and /var/run pid file exists
fi
fi
fi
if [ -x /bin/pidof -a ! "$specified" ]; then
/bin/pidof -o %PPID $1
status="$?"
[ "$status" = 1 ] && return 3 # program is not running
return 0
fi
return 4 # program or service is unknown
}
And this is the diff to the unstable version:
@@ -69,25 +71,31 @@
done
shift $(($OPTIND - 1))
- if [ -z "${pidfile:-}" ]; then
- pidfile=/var/run/${1##*/}.pid
+ base=${1##*/}
+ if [ ! "$specified" ]; then
+ pidfile="/var/run/$base.pid"
fi
- if [ -f "$pidfile" ]; then
+ if [ -n "${pidfile:-}" -a -e "$pidfile" ]; then
read pid < "$pidfile"
if [ -n "${pid:-}" ]; then
if $(kill -0 "${pid:-}" 2> /dev/null); then
echo "$pid"
return 0
+ elif ps "${pid:-}" >/dev/null 2>&1; then
+ echo "$pid"
+ return 0 # program is running, but not owned by this user
else
return 1 # program is dead and /var/run pid file exists
fi
fi
fi
if [ -x /bin/pidof -a ! "$specified" ]; then
- /bin/pidof -o %PPID $1
- status="$?"
- [ "$status" = 1 ] && return 3 # program is not running
+ status="0"
+ /bin/pidof -o %PPID -x $1 || status="$?"
+ if [ "$status" = 1 ]; then
+ return 3 # program is not running
+ fi
return 0
fi
return 4 # program or service is unknown
Happy hacking,
--
Petter Reinholdtsen
--
To UNSUBSCRIBE, email to debian-bugs-...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Hmhm yes that looks spurious. It's weird nobody noticed this before,
because it should break in many situations…
--
Yves-Alexis
I've tested the above patch and it seems to solve the problem. It took me
a couple of times reading though /lib/lsb/init-functions to understand why
though (use of $specified is confusing).
Also this problem doesn't seem to show in all circumstances. It shows up
on systems with and /etc/network/interfaces like:
auto lo eth0
iface lo inet loopback
iface eth0 inet dhcp
but not with:
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
(the second was on a machine that was more recently installed)
- --
- -- arthur - ade...@debian.org - http://people.debian.org/~adejong --
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFJLQ8xVYan35+NCKcRAiTYAKDl7aNSWNLKs+1ubN0+HrVicdmgEACfT8ox
f5uXIUK2j7k2Z1fgAoht2UA=
=/UbY
-----END PGP SIGNATURE-----