Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stumpish work on OpenBSD again #298

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

catap
Copy link
Contributor

@catap catap commented Nov 29, 2024

This fixes regression which was introduced by #296

@catap
Copy link
Contributor Author

catap commented Nov 29, 2024

@MIvanchev let move discussion here.

pgrep is part https://packages.debian.org/bookworm/procps on Debian which seems installed everywhere.

So, here a dramatic simplification of this function.

@MIvanchev
Copy link
Contributor

MIvanchev commented Nov 30, 2024

I'm suggesting this variant with a fallback for the hopefully rare case that there isn't a pgrep.

stumpwm_pid ()
{
    if command -v pgrep 2>&1 >/dev/null; then
        STUMPWM_PID=$(pgrep 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

    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
}

@catap
Copy link
Contributor Author

catap commented Nov 30, 2024

@MIvanchev here an updated PR.

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
stumpwm#296

Co-authored-by: Mihail Ivanchev <[email protected]>
@MIvanchev
Copy link
Contributor

I tested this in both cases and works good on Void Linux.

@MIvanchev
Copy link
Contributor

Thank you @catap !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants