aboutsummaryrefslogtreecommitdiff
path: root/toys/lsb
diff options
context:
space:
mode:
authorElie De Brauwer <eliedebrauwer@gmail.com>2012-12-08 20:10:05 +0100
committerElie De Brauwer <eliedebrauwer@gmail.com>2012-12-08 20:10:05 +0100
commit7c6209d6c336df74984e62aa88679c06641ae309 (patch)
treeb4bcc499ecfc4fe43ec6685803020f42c332e9c9 /toys/lsb
parentd394a1fb216b3a4653848f6625f8f731d7d34ac7 (diff)
downloadtoybox-7c6209d6c336df74984e62aa88679c06641ae309.tar.gz
Adding -s (single shot) and -o (omit pids) options to pidof
Diffstat (limited to 'toys/lsb')
-rw-r--r--toys/lsb/killall.c3
-rw-r--r--toys/lsb/pidof.c34
2 files changed, 33 insertions, 4 deletions
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c
index debc3dfc..2294f61d 100644
--- a/toys/lsb/killall.c
+++ b/toys/lsb/killall.c
@@ -25,7 +25,7 @@ GLOBALS(
int signum;
)
-static void kill_process(pid_t pid)
+static int kill_process(pid_t pid)
{
int ret;
@@ -33,6 +33,7 @@ static void kill_process(pid_t pid)
ret = kill(pid, TT.signum);
if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
+ return 1;
}
void killall_main(void)
diff --git a/toys/lsb/pidof.c b/toys/lsb/pidof.c
index 03643015..8aeb33e4 100644
--- a/toys/lsb/pidof.c
+++ b/toys/lsb/pidof.c
@@ -1,26 +1,54 @@
/* pidof.c - Print the Process IDs of all processes with the given names.
*
* Copyright 2012 Andreas Heck <aheck@gmx.de>
+ * Copyright 2012 Elie De Brauwer <eliedebrauwer@gmail.com>
*
* http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/pidof.html
-USE_PIDOF(NEWTOY(pidof, "<1", TOYFLAG_USR|TOYFLAG_BIN))
+USE_PIDOF(NEWTOY(pidof, "so:<1", TOYFLAG_USR|TOYFLAG_BIN))
config PIDOF
bool "pidof"
default y
help
- usage: pidof [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 omits processes with specified PID
*/
+#define FOR_pidof
#include "toys.h"
-static void print_pid(pid_t pid)
+GLOBALS(
+ char *omit;
+)
+
+static int print_pid(pid_t pid)
{
+
+ if (toys.optflags & FLAG_o)
+ {
+ char * res;
+ int len;
+ snprintf(toybuf, sizeof(toybuf), "%d", pid);
+ len = strlen(toybuf);
+ res = strstr(TT.omit, toybuf);
+ if (res &&
+ (res == TT.omit || res[-1] == ',') &&
+ (res[len] == ',' || res[len] == 0))
+ // Found in omit string
+ return 1;
+ }
+
xprintf("%s%ld", toys.exitval ? "" : " ", (long)pid);
toys.exitval = 0;
+
+ if (toys.optflags & FLAG_s)
+ return 0;
+
+ return 1;
}
void pidof_main(void)