pid_check: verify older PID's existence.

If $PIDFILE exists, verify whether it refers to a running
process. This way the amount of false positives is greatly
reduced, which is a good thing during development when
a crash can terminate sbopkg leaving the $PIDFILE in place.

Signed-off-by: Mauro Giachero <mauro.giachero@gmail.com>
This commit is contained in:
mauro.giachero 2009-01-22 11:28:16 +00:00
parent 52cbcbcbde
commit cd1f6aa495

View file

@ -133,20 +133,32 @@ directory_checks () {
pid_check () {
# Set and check for pid file.
local PIDFILE OTHERPID
PIDFILE=$TMP/sbopkg.pid
if [ -e $PIDFILE ]; then
# When things go haywire and sbopkg crashes (this happens only on
# development versions, of course ;-)) the PIDFILE isn't deleted and
# triggers the error below on the following run.
# Perform a basic test to reduce the amount of false positives. Note
# that no check on the file name is performed, to avoid missing true
# positives in the (rare, but possible) cases where the user renames
# the sbopkg script.
OTHERPID=$(cat $PIDFILE)
if [[ -n $(ps h --pid $OTHERPID) ]]; then
echo
echo "Another instance of sbopkg appears to be running"
echo "with process id $(cat $PIDFILE). Running more than"
echo "with process id $OTHERPID. Running more than"
echo "one instance of sbopkg is not recommended."
echo
echo "If this is incorrect, you can delete the lockfile"
echo "'${PIDFILE}' and restart. Exiting now."
exit 1
else
fi
fi
cleanup
echo $$ > $PIDFILE
fi
}
has_root () {