From 729256e857310de03508d970265bc5ac7fa1da62 Mon Sep 17 00:00:00 2001 From: "Kirill A. Korinsky" Date: Sat, 30 Nov 2024 10:38:02 +0100 Subject: [PATCH] Make stumpish work on OpenBSD again Seems that `pgrep` exists everywhere, for example in Debian it is installed from the same package which installs `ps` and `kill`. Use it as main way to detect stumpwm, and old code via /proc as a fallback when no `pgrep` here. This fixes regression which was introduced by https://github.com/stumpwm/stumpwm-contrib/pull/296 Co-authored-by: Mihail Ivanchev --- util/stumpish/stumpish | 43 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/util/stumpish/stumpish b/util/stumpish/stumpish index 3b8b2bb..396be9b 100755 --- a/util/stumpish/stumpish +++ b/util/stumpish/stumpish @@ -40,25 +40,32 @@ fi stumpwm_pid () { - local pid=$$ + if command -v pgrep 2>&1 >/dev/null; then + STUMPWM_PID=$(pgrep -u $(id -u) stumpwm) + elif [ -d /proc ]; then + # Go up the process chain until we locate StumpWM's process using + # the /proc virtual file system. + + local pid=$$ + + while [ $pid -ne 1 ] + do + if [ "$(cat /proc/${pid}/comm)" = "stumpwm" ]; then + STUMPWM_PID=$pid + break + else + pid=$(cut -f 4 -d " " < /proc/$pid/stat) + fi + done + fi - 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 [ "$(cat /proc/${pid}/comm)" = "stumpwm" ] - then - STUMPWM_PID=$pid - break - else - pid=$(cut -f 4 -d " " < /proc/$pid/stat) - fi - done + 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 ()