Mercurial > hg > toybox
comparison toys/killall.c @ 498:c9aaceccd6bd
Factor out common code between killall/kill and move it to lib/lib.c, plus cleanups on kill.c.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 26 Feb 2012 13:48:00 -0600 |
parents | 1a7110479d49 |
children |
comparison
equal
deleted
inserted
replaced
497:da73bb464ce8 | 498:c9aaceccd6bd |
---|---|
27 | 27 |
28 DEFINE_GLOBALS( | 28 DEFINE_GLOBALS( |
29 int signum; | 29 int signum; |
30 ) | 30 ) |
31 #define TT this.killall | 31 #define TT this.killall |
32 | |
33 struct signame { | |
34 int num; | |
35 char *name; | |
36 }; | |
37 | |
38 // Signals required by POSIX 2008: | |
39 // http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/signal.h.html | |
40 | |
41 #define SIGNIFY(x) {SIG##x, #x} | |
42 | |
43 static struct signame signames[] = { | |
44 SIGNIFY(ABRT), SIGNIFY(ALRM), SIGNIFY(BUS), SIGNIFY(CHLD), SIGNIFY(CONT), | |
45 SIGNIFY(FPE), SIGNIFY(HUP), SIGNIFY(ILL), SIGNIFY(INT), SIGNIFY(KILL), | |
46 SIGNIFY(PIPE), SIGNIFY(QUIT), SIGNIFY(SEGV), SIGNIFY(STOP), SIGNIFY(TERM), | |
47 SIGNIFY(TSTP), SIGNIFY(TTIN), SIGNIFY(TTOU), SIGNIFY(USR1), SIGNIFY(USR2), | |
48 SIGNIFY(SYS), SIGNIFY(TRAP), SIGNIFY(URG), SIGNIFY(VTALRM), SIGNIFY(XCPU), | |
49 SIGNIFY(XFSZ) | |
50 }; | |
51 | |
52 // SIGNIFY(STKFLT), SIGNIFY(WINCH), SIGNIFY(IO), SIGNIFY(PWR) | |
53 | |
54 // Convert name to signal number. If name == NULL print names. | |
55 static int sig_to_num(char *pidstr) | |
56 { | |
57 int i; | |
58 | |
59 if (pidstr) { | |
60 if (isdigit(*pidstr)) return atol(pidstr); | |
61 if (!strncasecmp(pidstr, "sig", 3)) pidstr+=3; | |
62 } | |
63 for (i = 0; i < sizeof(signames)/sizeof(struct signame); i++) | |
64 if (!pidstr) xputs(signames[i].name); | |
65 else if (!strcasecmp(pidstr, signames[i].name)) | |
66 return signames[i].num; | |
67 | |
68 return -1; | |
69 } | |
70 | 32 |
71 static void kill_process(pid_t pid) | 33 static void kill_process(pid_t pid) |
72 { | 34 { |
73 int ret; | 35 int ret; |
74 | 36 |