Skip to content

Commit 83f4374

Browse files
committed
Simplify stumpwm_pid by using only pgrep
Seems that `pgrep` exists everywhere, for example in Debian it is installed from the same package which installs `ps` and `kill`.
1 parent 63b62c6 commit 83f4374

File tree

1 file changed

+9
-32
lines changed

1 file changed

+9
-32
lines changed

util/stumpish/stumpish

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,15 @@ fi
4040

4141
stumpwm_pid ()
4242
{
43-
local pid=$$
44-
45-
while :
46-
do
47-
if [ $pid -eq 1 ]
48-
then
49-
echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2
50-
echo "session is running and StumpWM is your WM? If you think this is " 1>&2
51-
echo "a bug in stumpish, please report it." 1>&2
52-
echo 1>&2
53-
exit 1
54-
elif [ -e "/proc/${pid}/comm" -a "$(cat /proc/${pid}/comm 2>/dev/null)" = "stumpwm" ]
55-
then
56-
STUMPWM_PID=$pid
57-
break
58-
elif [ -n "$(which pgrep 2>/dev/null)" ]
59-
then
60-
pid=$(pgrep stumpwm)
61-
if [ -n $pid ]
62-
then
63-
STUMPWM_PID=$pid
64-
break
65-
else
66-
pid=1
67-
fi
68-
elif [ -e /proc/$pid/stat ]
69-
then
70-
pid=$(cut -f 4 -d " " < /proc/$pid/stat)
71-
else
72-
pid=1
73-
fi
74-
done
43+
STUMPWM_PID=$(pgrep stumpwm)
44+
45+
if [ -z "$STUMPWM_PID" ]; then
46+
echo "StumpWM not found in the process tree, are you sure a graphical " 1>&2
47+
echo "session is running and StumpWM is your WM? If you think this is " 1>&2
48+
echo "a bug in stumpish, please report it." 1>&2
49+
echo 1>&2
50+
exit 1
51+
fi
7552
}
7653

7754
wait_result ()

0 commit comments

Comments
 (0)