Mercurial > hg > toybox
annotate toys/killall.c @ 477:f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 18 Feb 2012 18:09:14 -0600 |
parents | 1fb149e75ebf |
children | 1a7110479d49 |
rev | line source |
---|---|
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
3 * killall.c - Send signal (default: TERM) to all processes with given names. |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * Copyright 2012 Andreas Heck <aheck@gmx.de> |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 * |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 * Not in SUSv4. |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
8 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
9 USE_KILLALL(NEWTOY(killall, "<1?lq", TOYFLAG_USR|TOYFLAG_BIN)) |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 config KILLALL |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 bool "killall" |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 default y |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 help |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 usage: killall [-l] [-q] [-SIG] PROCESS_NAME... |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 Send a signal (default: TERM) to all processes with the given names. |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 -l print list of all available signals |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 -q don't print any warnings or error messages |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 */ |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 #include "toys.h" |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 #define FLAG_q 1 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 #define FLAG_l 2 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 DEFINE_GLOBALS( |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
29 int matched; |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
30 int signum; |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 ) |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 #define TT this.killall |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 struct signame { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 int num; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 const char *name; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 }; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 static struct signame signames[] = { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 #ifdef SIGHUP |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 {SIGHUP, "HUP"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 #ifdef SIGINT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 {SIGINT, "INT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 #ifdef SIGQUIT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 {SIGQUIT, "QUIT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 #ifdef SIGILL |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 {SIGILL, "ILL"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 #ifdef SIGTRAP |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 {SIGTRAP, "TRAP"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 #ifdef SIGTABRT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 {SIGABRT, "ABRT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 #ifdef SIGTABRT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 {SIGIOT, "IOT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 #ifdef SIGBUS |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 {SIGBUS, "BUS"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 #ifdef SIGFPE |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 {SIGFPE, "FPE"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 #ifdef SIGKILL |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 {SIGKILL, "KILL"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 #ifdef SIGUSR1 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 {SIGUSR1, "USR1"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 #ifdef SIGSEGV |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 {SIGSEGV, "SEGV"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 #ifdef SIGUSR2 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 {SIGUSR2, "USR2"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 #ifdef SIGPIPE |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 {SIGPIPE, "PIPE"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 #ifdef SIGALRM |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 {SIGALRM, "ALRM"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 #ifdef SIGTERM |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 {SIGTERM, "TERM"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 #ifdef SIGSTKFLT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 {SIGSTKFLT, "STKFLT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 #ifdef SIGCHLD |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 {SIGCHLD, "CHLD"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 #ifdef SIGCONT |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 {SIGCONT, "CONT"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 #ifdef SIGSTOP |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 {SIGSTOP, "STOP"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 #ifdef SIGSTOP |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 {SIGSTOP, "STOP"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 #ifdef SIGTSTP |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 {SIGTSTP, "TSTP"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 #ifdef SIGTTIN |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 {SIGTTIN, "TTIN"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 #ifdef SIGTTOU |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 {SIGTTOU, "TTOU"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 #ifdef SIGURG |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 {SIGURG, "URG"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 #ifdef SIGXCPU |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 {SIGXCPU, "XCPU"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 #ifdef SIGXFSZ |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 {SIGXFSZ, "XFSZ"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 #ifdef SIGVTALRM |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 {SIGVTALRM, "VTALRM"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 #ifdef SIGVTALRM |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 {SIGVTALRM, "VTALRM"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 #ifdef SIGPROF |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 {SIGPROF, "PROF"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 #ifdef SIGWINCH |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 {SIGWINCH, "WINCH"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 #ifdef SIGIO |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 {SIGIO, "IO"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 #ifdef SIGPOLL |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 {SIGPOLL, "POLL"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 #ifdef SIGPWR |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 {SIGPWR, "PWR"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 #ifdef SIGSYS |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 {SIGSYS, "SYS"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
145 #ifdef SIGUNUSED |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
146 {SIGUNUSED, "UNUSED"}, |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
147 #endif |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 {0, NULL} |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 }; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
151 static int sig_to_num(const char *pidstr) |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
152 { |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
153 int i, num; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
154 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 if (isdigit(pidstr[0])) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 num = atoi(pidstr); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 return num; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
160 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 for (i = 0; signames[i].num; i++) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 if (strcmp(pidstr, signames[i].name) == 0) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 return signames[i].num; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 return -1; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
170 static void print_signals() |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
171 { |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 int i; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 for (i = 0; signames[i].num; i++) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 puts(signames[i].name); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
179 static void kill_process(pid_t pid) |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
180 { |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 int ret; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 TT.matched = 1; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 ret = kill(pid, TT.signum); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
186 if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill"); |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 void killall_main(void) |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
190 { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
191 char **names; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
192 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
193 TT.signum = SIGTERM; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
194 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
195 if (toys.optflags & FLAG_l) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
196 print_signals(); |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
197 return; |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
198 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
199 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
200 if (!*toys.optargs) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
201 toys.exithelp = 1; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
202 error_exit("Process name missing!"); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
203 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
204 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
205 names = toys.optargs; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
206 |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
207 if (**names == '-') { |
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
208 TT.signum = sig_to_num((*names)+1); |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
209 if (TT.signum <= 0) { |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
210 if (toys.optflags & FLAG_q) error_exit("Invalid signal"); |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
211 exit(1); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
212 } |
477
f0b07ce5f125
Cleanups to pidof (including some global infrastructure shared with killall).
Rob Landley <rob@landley.net>
parents:
475
diff
changeset
|
213 names++; |
475
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
214 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
215 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
216 if (!*names) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
217 toys.exithelp = 1; |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
218 error_exit("Process name missing!"); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
219 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
220 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 for_each_pid_with_name_in(names, kill_process); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 if (!TT.matched) { |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
224 if (!(toys.optflags & FLAG_q)) fprintf(stderr, "No such process\n"); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 exit(1); |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
226 } |
1fb149e75ebf
Add killall by Andreas Heck, and factor out common pid code to lib.h.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
227 } |