diff options
Diffstat (limited to 'kill.c')
-rw-r--r-- | kill.c | 142 |
1 files changed, 19 insertions, 123 deletions
@@ -34,96 +34,11 @@ | |||
34 | static const int KILL = 0; | 34 | static const int KILL = 0; |
35 | static const int KILLALL = 1; | 35 | static const int KILLALL = 1; |
36 | 36 | ||
37 | struct signal_name { | ||
38 | const char *name; | ||
39 | int number; | ||
40 | }; | ||
41 | |||
42 | static const struct signal_name signames[] = { | ||
43 | /* POSIX signals */ | ||
44 | { "HUP", SIGHUP }, /* 1 */ | ||
45 | { "INT", SIGINT }, /* 2 */ | ||
46 | { "QUIT", SIGQUIT }, /* 3 */ | ||
47 | { "ILL", SIGILL }, /* 4 */ | ||
48 | { "ABRT", SIGABRT }, /* 6 */ | ||
49 | { "FPE", SIGFPE }, /* 8 */ | ||
50 | { "KILL", SIGKILL }, /* 9 */ | ||
51 | { "SEGV", SIGSEGV }, /* 11 */ | ||
52 | { "PIPE", SIGPIPE }, /* 13 */ | ||
53 | { "ALRM", SIGALRM }, /* 14 */ | ||
54 | { "TERM", SIGTERM }, /* 15 */ | ||
55 | { "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */ | ||
56 | { "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */ | ||
57 | { "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */ | ||
58 | { "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */ | ||
59 | { "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */ | ||
60 | { "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */ | ||
61 | { "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */ | ||
62 | { "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */ | ||
63 | /* Miscellaneous other signals */ | ||
64 | #ifdef SIGTRAP | ||
65 | { "TRAP", SIGTRAP }, /* 5 */ | ||
66 | #endif | ||
67 | #ifdef SIGIOT | ||
68 | { "IOT", SIGIOT }, /* 6, same as SIGABRT */ | ||
69 | #endif | ||
70 | #ifdef SIGEMT | ||
71 | { "EMT", SIGEMT }, /* 7 (mips,alpha,sparc*) */ | ||
72 | #endif | ||
73 | #ifdef SIGBUS | ||
74 | { "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */ | ||
75 | #endif | ||
76 | #ifdef SIGSYS | ||
77 | { "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */ | ||
78 | #endif | ||
79 | #ifdef SIGSTKFLT | ||
80 | { "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */ | ||
81 | #endif | ||
82 | #ifdef SIGURG | ||
83 | { "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */ | ||
84 | #endif | ||
85 | #ifdef SIGIO | ||
86 | { "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */ | ||
87 | #endif | ||
88 | #ifdef SIGPOLL | ||
89 | { "POLL", SIGPOLL }, /* same as SIGIO */ | ||
90 | #endif | ||
91 | #ifdef SIGCLD | ||
92 | { "CLD", SIGCLD }, /* same as SIGCHLD (mips) */ | ||
93 | #endif | ||
94 | #ifdef SIGXCPU | ||
95 | { "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */ | ||
96 | #endif | ||
97 | #ifdef SIGXFSZ | ||
98 | { "XFSZ", SIGXFSZ }, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */ | ||
99 | #endif | ||
100 | #ifdef SIGVTALRM | ||
101 | { "VTALRM", SIGVTALRM }, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */ | ||
102 | #endif | ||
103 | #ifdef SIGPROF | ||
104 | { "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */ | ||
105 | #endif | ||
106 | #ifdef SIGPWR | ||
107 | { "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */ | ||
108 | #endif | ||
109 | #ifdef SIGINFO | ||
110 | { "INFO", SIGINFO }, /* 29 (alpha) */ | ||
111 | #endif | ||
112 | #ifdef SIGLOST | ||
113 | { "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */ | ||
114 | #endif | ||
115 | #ifdef SIGWINCH | ||
116 | { "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */ | ||
117 | #endif | ||
118 | #ifdef SIGUNUSED | ||
119 | { "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */ | ||
120 | #endif | ||
121 | {0, 0} | ||
122 | }; | ||
123 | 37 | ||
124 | extern int kill_main(int argc, char **argv) | 38 | extern int kill_main(int argc, char **argv) |
125 | { | 39 | { |
126 | int whichApp, sig = SIGTERM; | 40 | int whichApp, sig = SIGTERM; |
41 | const char *name; | ||
127 | 42 | ||
128 | #ifdef BB_KILLALL | 43 | #ifdef BB_KILLALL |
129 | /* Figure out what we are trying to do here */ | 44 | /* Figure out what we are trying to do here */ |
@@ -142,52 +57,37 @@ extern int kill_main(int argc, char **argv) | |||
142 | while (*++(*argv)) { | 57 | while (*++(*argv)) { |
143 | switch (**argv) { | 58 | switch (**argv) { |
144 | case 'l': | 59 | case 'l': |
145 | { | 60 | if(argc>1) { |
61 | for(argv++; *argv; argv++) { | ||
62 | name = u_signal_names(*argv, &sig, -1); | ||
63 | if(name!=NULL) | ||
64 | printf("%s\n", name); | ||
65 | } | ||
66 | } else { | ||
146 | int col = 0; | 67 | int col = 0; |
147 | const struct signal_name *s = signames; | 68 | for(sig=1; sig < NSIG; sig++) { |
148 | 69 | name = u_signal_names(0, &sig, 1); | |
149 | while (s->name != 0) { | 70 | if(name==NULL) /* unnamed */ |
150 | col += fprintf(stderr, "%2d) %-8s", s->number, s->name); | 71 | continue; |
151 | s++; | 72 | col += printf("%2d) %-16s", sig, name); |
152 | if (col > 60) { | 73 | if (col > 60) { |
153 | fprintf(stderr, "\n"); | 74 | printf("\n"); |
154 | col = 0; | 75 | col = 0; |
155 | } | 76 | } |
156 | } | 77 | } |
157 | fprintf(stderr, "\n\n"); | 78 | printf("\n"); |
158 | return EXIT_SUCCESS; | ||
159 | } | 79 | } |
160 | break; | 80 | return EXIT_SUCCESS; |
161 | case '-': | 81 | case '-': |
162 | show_usage(); | 82 | show_usage(); |
163 | default: | 83 | default: |
164 | { | 84 | name = u_signal_names(*argv, &sig, 0); |
165 | if (isdigit(**argv)) { | 85 | if(name==NULL) |
166 | sig = atoi(*argv); | 86 | error_msg_and_die( "bad signal name: %s", *argv); |
167 | if (sig < 0 || sig >= NSIG) | ||
168 | goto end; | ||
169 | else { | ||
170 | argc--; | ||
171 | argv++; | ||
172 | goto do_it_now; | ||
173 | } | ||
174 | } else { | ||
175 | const struct signal_name *s = signames; | ||
176 | |||
177 | while (s->name != 0) { | ||
178 | if (strcasecmp(s->name, *argv) == 0) { | ||
179 | sig = s->number; | ||
180 | argc--; | 87 | argc--; |
181 | argv++; | 88 | argv++; |
182 | goto do_it_now; | 89 | goto do_it_now; |
183 | } | 90 | } |
184 | s++; | ||
185 | } | ||
186 | if (s->name == 0) | ||
187 | goto end; | ||
188 | } | ||
189 | } | ||
190 | } | ||
191 | argc--; | 91 | argc--; |
192 | argv++; | 92 | argv++; |
193 | } | 93 | } |
@@ -239,8 +139,4 @@ extern int kill_main(int argc, char **argv) | |||
239 | #endif | 139 | #endif |
240 | 140 | ||
241 | return EXIT_SUCCESS; | 141 | return EXIT_SUCCESS; |
242 | |||
243 | |||
244 | end: | ||
245 | error_msg_and_die( "bad signal name: %s", *argv); | ||
246 | } | 142 | } |