Skip to content

replace ugly pidof | wc -l by pgrep

Submitted by Landry Breuil @landry

Assigned to Sean Davis @bluesabre

Link to original bug (#16591)

Description

seen this on OpenBSD while running in foreground:

[error_watch] gs-window-x11.c:892 (09:16:55.935): Command output: sh: pidof: not found

coming from https://git.xfce.org/apps/xfce4-screensaver/tree/src/gs-lock-plug.c#n174

pgrep does the same as pidof, and is present everywhere, while iirc pidof is linux only.

[23/03 09:52] landry@ansible.dmz:/infra $pidof ssh-agent 27409 24228 23463 23415 22800 21497 19770 19760 19755 19628 19609 19273 17903 15395 7843 7833 2425 356 [23/03 09:53] landry@ansible.dmz:/infra $pgrep ssh-agent 356 2425 7833 7843 15395 17903 19273 19609 19628 19755 19760 19770 21497 22800 23415 23463 24228 27409

and given that we merely try to detect if mdm, gdm, gdm3 or gdm-binary are running, we could avoid the uuuugly |wc -l and just check the return code of pgrep:

(on linux)

EXIT STATUS 0 One or more processes matched the criteria. For pkill the process must also have been successfully signalled. 1 No processes matched or none of them could be signalled. 2 Syntax error in the command line. 3 Fatal error: out of memory etc.

(on openbsd)

EXIT STATUS The pgrep and pkill utilities exit with one of the following values:

       0       One or more processes were matched.
       1       No processes were matched.
       2       Invalid options were specified on the command line.
       3       An internal error occurred.