Also modernize pidof.c, even though the bug was in lib. --- lib/lib.c | 3 ++- toys/lsb/pidof.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-)
From 2312b42012ebc86cc5b1887d632d3fd47d7ec23f Mon Sep 17 00:00:00 2001 From: Elliott Hughes <e...@google.com> Date: Tue, 5 Oct 2021 14:21:30 -0700 Subject: [PATCH] pidof: fix -s.
Also modernize pidof.c, even though the bug was in lib. --- lib/lib.c | 3 ++- toys/lsb/pidof.c | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/lib.c b/lib/lib.c index 332a0d01..0c1b5c37 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1164,9 +1164,10 @@ void names_to_pid(char **names, int (*callback)(pid_t pid, char *name), if (scripts && !strcmp(bb, getbasename(cmd+strlen(cmd)+1))) goto match; continue; match: - if (callback(u, *cur)) break; + if (callback(u, *cur)) goto done; } } +done: closedir(dp); } diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c index cd705a7c..791eed05 100644 --- a/toys/lsb/pidof.c +++ b/toys/lsb/pidof.c @@ -5,18 +5,18 @@ * * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html -USE_PIDOF(NEWTOY(pidof, "<1so:x", TOYFLAG_BIN)) +USE_PIDOF(NEWTOY(pidof, "so:x", TOYFLAG_BIN)) config PIDOF bool "pidof" default y help - usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME]... + usage: pidof [-s] [-o omitpid[,omitpid...]] [NAME...] Print the PIDs of all processes with the given names. - -s Single shot, only return one pid -o Omit PID(s) + -s Single shot, only return one pid -x Match shell scripts too */ @@ -24,17 +24,17 @@ config PIDOF #include "toys.h" GLOBALS( - char *omit; + char *o; ) static int print_pid(pid_t pid, char *name) { sprintf(toybuf, "%d", (int)pid); - if (comma_scan(TT.omit, toybuf, 0)) return 0; + if (comma_scan(TT.o, toybuf, 0)) return 0; xprintf(" %s"+!!toys.exitval, toybuf); toys.exitval = 0; - return toys.optflags & FLAG_s; + return FLAG(s); } void pidof_main(void) -- 2.33.0.882.g93a45727a2-goog
_______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net