diff options
Diffstat (limited to 'kill.c')
-rw-r--r-- | kill.c | 49 |
1 files changed, 25 insertions, 24 deletions
@@ -25,6 +25,7 @@ | |||
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include <unistd.h> | 26 | #include <unistd.h> |
27 | #include <signal.h> | 27 | #include <signal.h> |
28 | #include <ctype.h> | ||
28 | 29 | ||
29 | const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n"; | 30 | const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n"; |
30 | 31 | ||
@@ -112,47 +113,47 @@ const struct signal_name signames[] = { | |||
112 | 113 | ||
113 | extern int kill_main (int argc, char **argv) | 114 | extern int kill_main (int argc, char **argv) |
114 | { | 115 | { |
115 | int had_error = 0; | ||
116 | int sig = SIGTERM; | 116 | int sig = SIGTERM; |
117 | 117 | ||
118 | if ( argc < 2 ) | ||
119 | usage (kill_usage); | ||
118 | 120 | ||
119 | 121 | if ( **(argv+1) == '-' ) { | |
120 | if (argv[1][0] == '-') { | 122 | if (isdigit( *(*(++argv)+1) )) { |
121 | if (argv[1][1] >= '0' && argv[1][1] <= '9') { | 123 | sig = atoi (*argv); |
122 | sig = atoi (&argv[1][1]); | ||
123 | if (sig < 0 || sig >= NSIG) | 124 | if (sig < 0 || sig >= NSIG) |
124 | goto end; | 125 | goto end; |
125 | } else { | 126 | } |
127 | else { | ||
126 | const struct signal_name *s = signames; | 128 | const struct signal_name *s = signames; |
127 | for (;;) { | 129 | while (s->name != 0) { |
128 | if (strcmp (s->name, &argv[1][1]) == 0) { | 130 | if (strcasecmp (s->name, *argv+1) == 0) { |
129 | sig = s->number; | 131 | sig = s->number; |
130 | break; | 132 | break; |
131 | } | 133 | } |
132 | s++; | 134 | s++; |
133 | if (s->name == 0) | ||
134 | goto end; | ||
135 | } | 135 | } |
136 | if (s->name == 0) | ||
137 | goto end; | ||
136 | } | 138 | } |
137 | argv++; | ||
138 | argc--; | ||
139 | |||
140 | } | 139 | } |
141 | while (argc > 1) { | 140 | |
141 | while (--argc > 1) { | ||
142 | int pid; | 142 | int pid; |
143 | if (argv[1][0] < '0' || argv[1][0] > '9') | 143 | if (! isdigit( **(++argv))) { |
144 | goto end; | 144 | fprintf(stderr, "bad PID: %s\n", *argv); |
145 | pid = atoi (argv[1]); | 145 | exit( FALSE); |
146 | } | ||
147 | pid = atoi (*argv); | ||
146 | if (kill (pid, sig) != 0) { | 148 | if (kill (pid, sig) != 0) { |
147 | had_error = 1; | 149 | perror (*argv); |
148 | perror (argv[1]); | 150 | exit ( FALSE); |
149 | } | 151 | } |
150 | argv++; | ||
151 | argc--; | ||
152 | } | 152 | } |
153 | if (had_error) { | 153 | |
154 | end: | 154 | end: |
155 | usage (kill_usage); | 155 | fprintf(stderr, "bad signal name: %s\n", *argv); |
156 | } | ||
157 | exit (TRUE); | 156 | exit (TRUE); |
158 | } | 157 | } |
158 | |||
159 | |||