From cd1f6aa4959570bdedbb9ef62a780214cfac3b90 Mon Sep 17 00:00:00 2001 From: "mauro.giachero" Date: Thu, 22 Jan 2009 11:28:16 +0000 Subject: [PATCH] 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 --- src/usr/bin/sbopkg | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/usr/bin/sbopkg b/src/usr/bin/sbopkg index e860e73..41c71aa 100755 --- a/src/usr/bin/sbopkg +++ b/src/usr/bin/sbopkg @@ -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 - echo - echo "Another instance of sbopkg appears to be running" - echo "with process id $(cat $PIDFILE). 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 - cleanup - echo $$ > $PIDFILE + # 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 $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 + fi fi + + cleanup + echo $$ > $PIDFILE } has_root () {