changeset 1142:1e4e707fc0bc draft

Fix pidof -o bug aborting output, reported by Ashwini Sharma.
author Rob Landley <rob@landley.net>
date Mon, 16 Dec 2013 17:41:25 -0600
parents 37cbbbe547a3
children 2115856395e2
files toys/lsb/pidof.c
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/toys/lsb/pidof.c	Sun Dec 08 13:26:05 2013 -0600
+++ b/toys/lsb/pidof.c	Mon Dec 16 17:41:25 2013 -0600
@@ -11,11 +11,12 @@
   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	omits processes with specified PID
+    -o	omit PID(s)
 */
 
 #define FOR_pidof
@@ -25,21 +26,19 @@
   char *omit;
 )
 
-static int print_pid(pid_t pid, char * name)
+static int print_pid(pid_t pid, char *name)
 {
   char * res;
   int len;
 
-  sprintf(toybuf, "%d", pid);
+  sprintf(toybuf, "%d", (int)pid);
   len = strlen(toybuf);
 
   // Check omit string
-  if (toys.optflags & FLAG_o)
-  {
-    res = strstr(TT.omit, toybuf);
-    if (res && (res == TT.omit || res[-1] == ',') &&
-      (res[len] == ',' || res[len] == 0)) return 1;
-  }
+  if (TT.omit && (res = strstr(TT.omit, toybuf)))
+    if ((res == TT.omit || res[-1] == ',') &&
+      (res[len] == ',' || !res[len])) return 0;
+
   xprintf("%*s", len+(!toys.exitval), toybuf);
   toys.exitval = 0;