Skip to content

Commit

Permalink
Simplify stumpwm_pid by using only pgrep
Browse files Browse the repository at this point in the history
Seems that `pgrep` exists everywhere, for example in Debian it is
installed from the same package which installs `ps` and `kill`.
  • Loading branch information
catap committed Nov 29, 2024
1 parent 63b62c6 commit 83f4374
Showing 1 changed file with 9 additions and 32 deletions.
41 changes: 9 additions & 32 deletions util/stumpish/stumpish
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,15 @@ fi

stumpwm_pid ()
{
local pid=$$

while :
do
if [ $pid -eq 1 ]
then
echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2
echo "session is running and StumpWM is your WM? If you think this is " 1>&2
echo "a bug in stumpish, please report it." 1>&2
echo 1>&2
exit 1
elif [ -e "/proc/${pid}/comm" -a "$(cat /proc/${pid}/comm 2>/dev/null)" = "stumpwm" ]
then
STUMPWM_PID=$pid
break
elif [ -n "$(which pgrep 2>/dev/null)" ]
then
pid=$(pgrep stumpwm)
if [ -n $pid ]
then
STUMPWM_PID=$pid
break
else
pid=1
fi
elif [ -e /proc/$pid/stat ]
then
pid=$(cut -f 4 -d " " < /proc/$pid/stat)
else
pid=1
fi
done
STUMPWM_PID=$(pgrep stumpwm)

if [ -z "$STUMPWM_PID" ]; then
echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2
echo "session is running and StumpWM is your WM? If you think this is " 1>&2
echo "a bug in stumpish, please report it." 1>&2
echo 1>&2
exit 1
fi
}

wait_result ()
Expand Down

0 comments on commit 83f4374

Please sign in to comment.