Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
1056:2b35f9c797ad | 1057:242c5de2bb22 |
---|---|
30 | 30 |
31 static int kill_process(pid_t pid, char *name) | 31 static int kill_process(pid_t pid, char *name) |
32 { | 32 { |
33 int ret; | 33 int ret; |
34 | 34 |
35 if (pid == TT.cur_pid) return 1; | 35 if (pid == TT.cur_pid) return 0; |
36 | 36 |
37 if (toys.optflags & FLAG_i) { | 37 if (toys.optflags & FLAG_i) { |
38 sprintf(toybuf, "Signal %s(%d) ?", name, pid); | 38 sprintf(toybuf, "Signal %s(%d) ?", name, pid); |
39 if (yesno(toybuf, 0) == 0) return 1; | 39 if (yesno(toybuf, 0) == 0) return 0; |
40 } | 40 } |
41 | 41 |
42 toys.exitval = 0; | |
43 | |
44 ret = kill(pid, TT.signum); | 42 ret = kill(pid, TT.signum); |
45 if (toys.optflags & FLAG_v) | 43 if (ret == -1 && !(toys.optflags & FLAG_q)) |
44 error_msg("bad %u", (unsigned)pid); | |
45 else if (toys.optflags & FLAG_v) | |
46 printf("Killed %s(%d) with signal %d\n", name, pid, TT.signum); | 46 printf("Killed %s(%d) with signal %d\n", name, pid, TT.signum); |
47 | 47 |
48 if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill"); | 48 return 0; |
49 return 1; | |
50 } | 49 } |
51 | 50 |
52 void killall_main(void) | 51 void killall_main(void) |
53 { | 52 { |
54 char **names = toys.optargs; | 53 char **names = toys.optargs; |
74 error_exit("Process name missing!"); | 73 error_exit("Process name missing!"); |
75 } | 74 } |
76 | 75 |
77 TT.cur_pid = getpid(); | 76 TT.cur_pid = getpid(); |
78 | 77 |
79 for_each_pid_with_name_in(names, kill_process); | 78 names_to_pid(names, kill_process); |
80 | 79 |
81 if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process"); | 80 if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process"); |
82 } | 81 } |