comparison toys/lsb/killall.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 7e846e281e38
children 99ca30ad3d2b
comparison
equal deleted inserted replaced
693:4a5a250e0633 694:786841fdb1e0
1 /* vi: set sw=4 ts=4: 1 /* killall.c - Send signal (default: TERM) to all processes with given names.
2 *
3 * killall.c - Send signal (default: TERM) to all processes with given names.
4 * 2 *
5 * Copyright 2012 Andreas Heck <aheck@gmx.de> 3 * Copyright 2012 Andreas Heck <aheck@gmx.de>
6 * 4 *
7 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/killall.html 5 * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/killall.html
8 6
9 USE_KILLALL(NEWTOY(killall, "<1?lq", TOYFLAG_USR|TOYFLAG_BIN)) 7 USE_KILLALL(NEWTOY(killall, "<1?lq", TOYFLAG_USR|TOYFLAG_BIN))
10 8
11 config KILLALL 9 config KILLALL
12 bool "killall" 10 bool "killall"
13 default y 11 default y
14 help 12 help
15 usage: killall [-l] [-q] [-SIG] PROCESS_NAME... 13 usage: killall [-l] [-q] [-SIG] PROCESS_NAME...
16 14
17 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.
18 16
19 -l print list of all available signals 17 -l print list of all available signals
20 -q don't print any warnings or error messages 18 -q don't print any warnings or error messages
21 */ 19 */
22 20
23 #define FOR_killall 21 #define FOR_killall
24 #include "toys.h" 22 #include "toys.h"
25 23
26 GLOBALS( 24 GLOBALS(
27 int signum; 25 int signum;
28 ) 26 )
29 27
30 static void kill_process(pid_t pid) 28 static void kill_process(pid_t pid)
31 { 29 {
32 int ret; 30 int ret;
33 31
34 toys.exitval = 0; 32 toys.exitval = 0;
35 ret = kill(pid, TT.signum); 33 ret = kill(pid, TT.signum);
36 34
37 if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill"); 35 if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill");
38 } 36 }
39 37
40 void killall_main(void) 38 void killall_main(void)
41 { 39 {
42 char **names; 40 char **names;
43 41
44 if (toys.optflags & FLAG_l) { 42 if (toys.optflags & FLAG_l) {
45 sig_to_num(NULL); 43 sig_to_num(NULL);
46 return; 44 return;
47 } 45 }
48 46
49 TT.signum = SIGTERM; 47 TT.signum = SIGTERM;
50 toys.exitval++; 48 toys.exitval++;
51 49
52 if (!*toys.optargs) { 50 if (!*toys.optargs) {
53 toys.exithelp = 1; 51 toys.exithelp = 1;
54 error_exit("Process name missing!"); 52 error_exit("Process name missing!");
55 } 53 }
56 54
57 names = toys.optargs; 55 names = toys.optargs;
58 56
59 if (**names == '-') { 57 if (**names == '-') {
60 if (0 > (TT.signum = sig_to_num((*names)+1))) { 58 if (0 > (TT.signum = sig_to_num((*names)+1))) {
61 if (toys.optflags & FLAG_q) exit(1); 59 if (toys.optflags & FLAG_q) exit(1);
62 error_exit("Invalid signal"); 60 error_exit("Invalid signal");
63 } 61 }
64 names++; 62 names++;
65 63
66 if (!*names) { 64 if (!*names) {
67 toys.exithelp++; 65 toys.exithelp++;
68 error_exit("Process name missing!"); 66 error_exit("Process name missing!");
69 } 67 }
70 } 68 }
71 69
72 for_each_pid_with_name_in(names, kill_process); 70 for_each_pid_with_name_in(names, kill_process);
73 71
74 if (toys.exitval && !(toys.optflags & FLAG_q)) 72 if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process");
75 error_exit("No such process");
76 } 73 }