comparison toys/lsb/killall.c @ 767:979d038c1688

Minor cleanups.
author Rob Landley <rob@landley.net>
date Sun, 23 Dec 2012 15:07:28 -0600
parents 5d435b48da8d
children 242c5de2bb22
comparison
equal deleted inserted replaced
766:5d435b48da8d 767:979d038c1688
8 8
9 config KILLALL 9 config KILLALL
10 bool "killall" 10 bool "killall"
11 default y 11 default y
12 help 12 help
13 usage: killall [-l] [-qv] [-SIG] PROCESS_NAME... 13 usage: killall [-l] [-iqv] [-SIG] PROCESS_NAME...
14 14
15 Send a signal (default: TERM) to all processes with the given names. 15 Send a signal (default: TERM) to all processes with the given names.
16 16
17 -i ask for confirmation before killing
17 -l print list of all available signals 18 -l print list of all available signals
18 -i ask for confirmation before killing 19 -q don't print any warnings or error messages
19 -v report if the signal was successfully sent 20 -v report if the signal was successfully sent
20 -q don't print any warnings or error messages
21 */ 21 */
22 22
23 #define FOR_killall 23 #define FOR_killall
24 #include "toys.h" 24 #include "toys.h"
25 25
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 1;
36 36
37 if(toys.optflags & FLAG_i) { 37 if (toys.optflags & FLAG_i) {
38 snprintf(toybuf, sizeof(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 1;
40 } 40 }
41 41
42 toys.exitval = 0; 42 toys.exitval = 0;
43 43
49 return 1; 49 return 1;
50 } 50 }
51 51
52 void killall_main(void) 52 void killall_main(void)
53 { 53 {
54 char **names; 54 char **names = toys.optargs;
55
56 TT.signum = SIGTERM;
57 toys.exitval++;
55 58
56 if (toys.optflags & FLAG_l) { 59 if (toys.optflags & FLAG_l) {
57 sig_to_num(NULL); 60 sig_to_num(NULL);
58 return; 61 return;
59 } 62 }
60
61 TT.signum = SIGTERM;
62 toys.exitval++;
63
64 if (!*toys.optargs) {
65 toys.exithelp++;
66 error_exit("Process name missing!");
67 }
68
69 names = toys.optargs;
70 63
71 if (**names == '-') { 64 if (**names == '-') {
72 if (0 > (TT.signum = sig_to_num((*names)+1))) { 65 if (0 > (TT.signum = sig_to_num((*names)+1))) {
73 if (toys.optflags & FLAG_q) exit(1); 66 if (toys.optflags & FLAG_q) exit(1);
74 error_exit("Invalid signal"); 67 error_exit("Invalid signal");
75 } 68 }
76 names++; 69 names++;
70 }
77 71
78 if (!*names) { 72 if (!*names) {
79 toys.exithelp++; 73 toys.exithelp++;
80 error_exit("Process name missing!"); 74 error_exit("Process name missing!");
81 }
82 } 75 }
83 76
84 TT.cur_pid = getpid(); 77 TT.cur_pid = getpid();
85 78
86 for_each_pid_with_name_in(names, kill_process); 79 for_each_pid_with_name_in(names, kill_process);