From e7229e669cf3a00180478c57ad60ba07019e670c Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Sat, 30 Dec 2023 09:52:31 +0100 Subject: [PATCH] xsession-daemon: More robust proc detection Test for running process with given PID was instable. Replace with pid-file feature of pgrep. --- xsession-daemon | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/xsession-daemon b/xsession-daemon index f7edb63..247c903 100755 --- a/xsession-daemon +++ b/xsession-daemon @@ -22,33 +22,29 @@ PIDDIR="${PIDFILE%/*}" LOGDIR="${LOGFILE%/*}" mkdir -p $PIDDIR -if [ $? -ne 0 ]; -then +if [ $? -ne 0 ]; then echo "Session daemon PIDDIR not there: $PIDDIR" >&2 exit 2 fi mkdir -p $LOGDIR -if [ $? -ne 0 ]; -then +if [ $? -ne 0 ]; then echo "Session daemon LOGDIR not there: $LOGDIR" >&2 exit 2 fi -if [ -e "$PIDFILE" ] ; -then - echo "Session daemon '$NAME' PIDFILE found: $PIDFILE" - PID=`cat "$PIDFILE"` +if [ -e "$PIDFILE" ] ; then + PID=`cat "$PIDFILE"` echo "Session daemon '$NAME' PID found: $PID" + + if pgrep -F "$PIDFILE" "${NAME}" >/dev/null ; then + echo "Session daemon '$NAME' was already running with PID $PID" >&2 + exit 3 + fi else echo "Session daemon '$NAME' PIDFILE NOT found: $PIDFILE" fi -if [ "$PID" ] && kill -0 "$PID" 2>/dev/null ; -then - echo "Session daemon '$NAME' was already running with PID $PID" >&2 - exit 3 -fi echo "Session daemon running $COMMAND $* > $LOGFILE 2>&1" $COMMAND $* > "$LOGFILE" 2>&1 & @@ -56,8 +52,7 @@ PID=$! ERR=$? sleep 1 -if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev/null; -then +if [ "$PID" ] && [ $ERR == 0 ] && kill -0 "$PID" 2>/dev/null; then echo -n $PID > "$PIDFILE" echo "Session daemon '$NAME' started with PID $PID" else -- 2.30.2