diff toys/lsb/killall.c @ 1057:242c5de2bb22 draft

Replace for_each_pid_with_name_in_array_perform_callback_function_upon_translated_value() with name_to_pid(), comparing absolute paths or just basename() consistently as spotted by Lukasz Skalski, and adjust callers.
author Rob Landley <rob@landley.net>
date Tue, 03 Sep 2013 18:43:32 -0500
parents 979d038c1688
children a9374aa2631a
line wrap: on
line diff
--- a/toys/lsb/killall.c	Thu Sep 05 23:58:35 2013 -0500
+++ b/toys/lsb/killall.c	Tue Sep 03 18:43:32 2013 -0500
@@ -32,21 +32,20 @@
 {
   int ret;
 
-  if (pid == TT.cur_pid) return 1;
+  if (pid == TT.cur_pid) return 0;
 
   if (toys.optflags & FLAG_i) {
     sprintf(toybuf, "Signal %s(%d) ?", name, pid);
-    if (yesno(toybuf, 0) == 0) return 1;
+    if (yesno(toybuf, 0) == 0) return 0;
   }
 
-  toys.exitval = 0;
-
   ret = kill(pid, TT.signum);
-  if (toys.optflags & FLAG_v)
+  if (ret == -1 && !(toys.optflags & FLAG_q))
+    error_msg("bad %u", (unsigned)pid);
+  else if (toys.optflags & FLAG_v)
     printf("Killed %s(%d) with signal %d\n", name, pid, TT.signum);
 
-  if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
-  return 1;
+  return 0;
 }
 
 void killall_main(void)
@@ -76,7 +75,7 @@
 
   TT.cur_pid = getpid();
 
-  for_each_pid_with_name_in(names, kill_process);
+  names_to_pid(names, kill_process);
 
   if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process");
 }