comparison toys/lsb/killall.c @ 1154:f7b777035025 draft

Add -s option, allow zero optargs for -l. (Suggested by Ashwini Sharma.)
author Rob Landley <rob@landley.net>
date Sun, 22 Dec 2013 19:39:12 -0600
parents a9374aa2631a
children d965dfbee154
comparison
equal deleted inserted replaced
1153:c4ac6a90963d 1154:f7b777035025
2 * 2 *
3 * Copyright 2012 Andreas Heck <aheck@gmx.de> 3 * Copyright 2012 Andreas Heck <aheck@gmx.de>
4 * 4 *
5 * 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
6 6
7 USE_KILLALL(NEWTOY(killall, "<1?lqvi", TOYFLAG_USR|TOYFLAG_BIN)) 7 USE_KILLALL(NEWTOY(killall, "?s:lqvi", TOYFLAG_USR|TOYFLAG_BIN))
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] [-iqv] [-SIG] PROCESS_NAME... 13 usage: killall [-l] [-iqv] [-SIGNAL|-s SIGNAL] 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 -i ask for confirmation before killing
18 -l print list of all available signals 18 -l print list of all available signals
19 -q don't print any warnings or error messages 19 -q don't print any warnings or error messages
20 -s send SIGNAL instead of SIGTERM
20 -v report if the signal was successfully sent 21 -v report if the signal was successfully sent
21 */ 22 */
22 23
23 #define FOR_killall 24 #define FOR_killall
24 #include "toys.h" 25 #include "toys.h"
25 26
26 GLOBALS( 27 GLOBALS(
28 char *sig;
29
27 int signum; 30 int signum;
28 pid_t cur_pid; 31 pid_t cur_pid;
29 char **names; 32 char **names;
30 short *err; 33 short *err;
31 ) 34 )
67 if (toys.optflags & FLAG_l) { 70 if (toys.optflags & FLAG_l) {
68 sig_to_num(NULL); 71 sig_to_num(NULL);
69 return; 72 return;
70 } 73 }
71 74
72 if (**TT.names == '-') { 75 if (TT.sig || **TT.names == '-') {
73 if (0 > (TT.signum = sig_to_num((*TT.names)+1))) { 76 if (0 > (TT.signum = sig_to_num(TT.sig ? TT.sig : (*TT.names)+1))) {
74 if (toys.optflags & FLAG_q) exit(1); 77 if (toys.optflags & FLAG_q) exit(1);
75 error_exit("Invalid signal"); 78 error_exit("Invalid signal");
76 } 79 }
77 TT.names++; 80 if (!TT.sig) {
78 toys.optc--; 81 TT.names++;
82 toys.optc--;
83 }
79 } 84 }
80 85
81 if (!toys.optc) { 86 if (!(toys.optflags & FLAG_l) && !toys.optc) {
82 toys.exithelp++; 87 toys.exithelp++;
83 error_exit("no name"); 88 error_exit("no name");
84 } 89 }
85 90
86 TT.cur_pid = getpid(); 91 TT.cur_pid = getpid();