Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 2 | /* |
Denis Vlasenko | 02f47e9 | 2007-05-06 22:48:55 +0000 | [diff] [blame] | 3 | * Mini kill/killall[5] implementation for busybox |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 7 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 11 | //usage:#define kill_trivial_usage |
| 12 | //usage: "[-l] [-SIG] PID..." |
| 13 | //usage:#define kill_full_usage "\n\n" |
| 14 | //usage: "Send a signal (default: TERM) to given PIDs\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 15 | //usage: "\n -l List all signal names and numbers" |
| 16 | /* //usage: "\n -s SIG Yet another way of specifying SIG" */ |
| 17 | //usage: |
| 18 | //usage:#define kill_example_usage |
| 19 | //usage: "$ ps | grep apache\n" |
| 20 | //usage: "252 root root S [apache]\n" |
| 21 | //usage: "263 www-data www-data S [apache]\n" |
| 22 | //usage: "264 www-data www-data S [apache]\n" |
| 23 | //usage: "265 www-data www-data S [apache]\n" |
| 24 | //usage: "266 www-data www-data S [apache]\n" |
| 25 | //usage: "267 www-data www-data S [apache]\n" |
| 26 | //usage: "$ kill 252\n" |
| 27 | //usage: |
| 28 | //usage:#define killall_trivial_usage |
| 29 | //usage: "[-l] [-q] [-SIG] PROCESS_NAME..." |
| 30 | //usage:#define killall_full_usage "\n\n" |
| 31 | //usage: "Send a signal (default: TERM) to given processes\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 32 | //usage: "\n -l List all signal names and numbers" |
| 33 | /* //usage: "\n -s SIG Yet another way of specifying SIG" */ |
| 34 | //usage: "\n -q Don't complain if no processes were killed" |
| 35 | //usage: |
| 36 | //usage:#define killall_example_usage |
| 37 | //usage: "$ killall apache\n" |
| 38 | //usage: |
| 39 | //usage:#define killall5_trivial_usage |
| 40 | //usage: "[-l] [-SIG] [-o PID]..." |
| 41 | //usage:#define killall5_full_usage "\n\n" |
| 42 | //usage: "Send a signal (default: TERM) to all processes outside current session\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 43 | //usage: "\n -l List all signal names and numbers" |
| 44 | //usage: "\n -o PID Don't signal this PID" |
| 45 | /* //usage: "\n -s SIG Yet another way of specifying SIG" */ |
| 46 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 47 | #include "libbb.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 48 | |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 49 | /* Note: kill_main is directly called from shell in order to implement |
| 50 | * kill built-in. Shell substitutes job ids with process groups first. |
| 51 | * |
| 52 | * This brings some complications: |
| 53 | * |
| 54 | * + we can't use xfunc here |
| 55 | * + we can't use applet_name |
| 56 | * + we can't use bb_show_usage |
| 57 | * (Above doesn't apply for killall[5] cases) |
| 58 | * |
| 59 | * kill %n gets translated into kill ' -<process group>' by shell (note space!) |
| 60 | * This is needed to avoid collision with kill -9 ... syntax |
| 61 | */ |
| 62 | |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 63 | int kill_main(int argc UNUSED_PARAM, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 64 | { |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 65 | char *arg; |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 66 | pid_t pid; |
| 67 | int signo = SIGTERM, errors = 0, quiet = 0; |
Denis Vlasenko | 02f47e9 | 2007-05-06 22:48:55 +0000 | [diff] [blame] | 68 | #if !ENABLE_KILLALL && !ENABLE_KILLALL5 |
| 69 | #define killall 0 |
| 70 | #define killall5 0 |
| 71 | #else |
| 72 | /* How to determine who we are? find 3rd char from the end: |
| 73 | * kill, killall, killall5 |
Denis Vlasenko | 0cacc80 | 2007-05-06 22:51:52 +0000 | [diff] [blame] | 74 | * ^i ^a ^l - it's unique |
| 75 | * (checking from the start is complicated by /bin/kill... case) */ |
Denis Vlasenko | 02f47e9 | 2007-05-06 22:48:55 +0000 | [diff] [blame] | 76 | const char char3 = argv[0][strlen(argv[0]) - 3]; |
| 77 | #define killall (ENABLE_KILLALL && char3 == 'a') |
| 78 | #define killall5 (ENABLE_KILLALL5 && char3 == 'l') |
| 79 | #endif |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 80 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 81 | /* Parse any options */ |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 82 | arg = *++argv; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 83 | |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 84 | if (!arg || arg[0] != '-') { |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 85 | goto do_it_now; |
| 86 | } |
| 87 | |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 88 | /* The -l option, which prints out signal names. |
| 89 | * Intended usage in shell: |
| 90 | * echo "Died of SIG`kill -l $?`" |
| 91 | * We try to mimic what kill from coreutils-6.8 does */ |
Denis Vlasenko | fa07680 | 2006-11-05 00:38:51 +0000 | [diff] [blame] | 92 | if (arg[1] == 'l' && arg[2] == '\0') { |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 93 | arg = *++argv; |
| 94 | if (!arg) { |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 95 | /* Print the whole signal list */ |
Denis Vlasenko | a4f4de9 | 2007-09-30 16:32:01 +0000 | [diff] [blame] | 96 | print_signames(); |
| 97 | return 0; |
Denis Vlasenko | 72e1c89 | 2007-09-29 22:26:01 +0000 | [diff] [blame] | 98 | } |
| 99 | /* -l <sig list> */ |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 100 | do { |
Denis Vlasenko | 72e1c89 | 2007-09-29 22:26:01 +0000 | [diff] [blame] | 101 | if (isdigit(arg[0])) { |
| 102 | signo = bb_strtou(arg, NULL, 10); |
| 103 | if (errno) { |
| 104 | bb_error_msg("unknown signal '%s'", arg); |
| 105 | return EXIT_FAILURE; |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 106 | } |
Denis Vlasenko | 72e1c89 | 2007-09-29 22:26:01 +0000 | [diff] [blame] | 107 | /* Exitcodes >= 0x80 are to be treated |
| 108 | * as "killed by signal (exitcode & 0x7f)" */ |
| 109 | puts(get_signame(signo & 0x7f)); |
| 110 | /* TODO: 'bad' signal# - coreutils says: |
| 111 | * kill: 127: invalid signal |
| 112 | * we just print "127" instead */ |
| 113 | } else { |
| 114 | signo = get_signum(arg); |
| 115 | if (signo < 0) { |
| 116 | bb_error_msg("unknown signal '%s'", arg); |
| 117 | return EXIT_FAILURE; |
| 118 | } |
| 119 | printf("%d\n", signo); |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 120 | } |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 121 | arg = *++argv; |
| 122 | } while (arg); |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 123 | return EXIT_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | /* The -q quiet option */ |
Denis Vlasenko | fa07680 | 2006-11-05 00:38:51 +0000 | [diff] [blame] | 127 | if (killall && arg[1] == 'q' && arg[2] == '\0') { |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 128 | quiet = 1; |
| 129 | arg = *++argv; |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 130 | if (!arg) |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 131 | bb_show_usage(); |
| 132 | if (arg[0] != '-') |
| 133 | goto do_it_now; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 134 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 135 | |
Denis Vlasenko | b9b344a | 2008-10-31 00:30:48 +0000 | [diff] [blame] | 136 | arg++; /* skip '-' */ |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 137 | |
| 138 | /* -o PID? (if present, it always is at the end of command line) */ |
| 139 | if (killall5 && arg[0] == 'o') |
| 140 | goto do_it_now; |
| 141 | |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 142 | if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ |
Denis Vlasenko | b9b344a | 2008-10-31 00:30:48 +0000 | [diff] [blame] | 143 | arg = *++argv; |
| 144 | } /* else it must be -SIG */ |
| 145 | signo = get_signum(arg); |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 146 | if (signo < 0) { /* || signo > MAX_SIGNUM ? */ |
Denis Vlasenko | b9b344a | 2008-10-31 00:30:48 +0000 | [diff] [blame] | 147 | bb_error_msg("bad signal name '%s'", arg); |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 148 | return EXIT_FAILURE; |
| 149 | } |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 150 | arg = *++argv; |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 151 | |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 152 | do_it_now: |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 153 | pid = getpid(); |
Eric Andersen | abc0f4f | 1999-12-08 23:19:36 +0000 | [diff] [blame] | 154 | |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 155 | if (killall5) { |
| 156 | pid_t sid; |
Denis Vlasenko | 459e4d6 | 2006-11-05 00:43:51 +0000 | [diff] [blame] | 157 | procps_status_t* p = NULL; |
Uros Vampl | 3ac1e0d | 2013-12-16 17:44:58 +0100 | [diff] [blame] | 158 | /* compat: exitcode 2 is "no one was signaled" */ |
| 159 | int ret = 2; |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 160 | |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 161 | /* Find out our session id */ |
Denis Vlasenko | 6b06cb8 | 2008-05-15 21:30:45 +0000 | [diff] [blame] | 162 | sid = getsid(pid); |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 163 | /* Stop all processes */ |
Denys Vlasenko | 1485030 | 2012-04-03 08:16:05 +0200 | [diff] [blame] | 164 | if (signo != SIGSTOP && signo != SIGCONT) |
| 165 | kill(-1, SIGSTOP); |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 166 | /* Signal all processes except those in our session */ |
Alexey Fomenko | 6a93212 | 2011-12-22 11:38:57 +0100 | [diff] [blame] | 167 | while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID)) != NULL) { |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 168 | char **args; |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 169 | |
| 170 | if (p->sid == (unsigned)sid |
Uros Vampl | 3ac1e0d | 2013-12-16 17:44:58 +0100 | [diff] [blame] | 171 | || p->sid == 0 /* compat: kernel thread, don't signal it */ |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 172 | || p->pid == (unsigned)pid |
Alexey Fomenko | 6a93212 | 2011-12-22 11:38:57 +0100 | [diff] [blame] | 173 | || p->pid == 1 |
| 174 | ) { |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 175 | continue; |
Alexey Fomenko | 6a93212 | 2011-12-22 11:38:57 +0100 | [diff] [blame] | 176 | } |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 177 | |
| 178 | /* All remaining args must be -o PID options. |
| 179 | * Check p->pid against them. */ |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 180 | args = argv; |
| 181 | while (*args) { |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 182 | pid_t omit; |
| 183 | |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 184 | arg = *args++; |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 185 | if (arg[0] != '-' || arg[1] != 'o') { |
| 186 | bb_error_msg("bad option '%s'", arg); |
| 187 | ret = 1; |
| 188 | goto resume; |
| 189 | } |
| 190 | arg += 2; |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 191 | if (!arg[0] && *args) |
| 192 | arg = *args++; |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 193 | omit = bb_strtoi(arg, NULL, 10); |
| 194 | if (errno) { |
Denys Vlasenko | b32a543 | 2010-08-29 13:29:02 +0200 | [diff] [blame] | 195 | bb_error_msg("invalid number '%s'", arg); |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 196 | ret = 1; |
| 197 | goto resume; |
| 198 | } |
| 199 | if (p->pid == omit) |
| 200 | goto dont_kill; |
| 201 | } |
| 202 | kill(p->pid, signo); |
Uros Vampl | 3ac1e0d | 2013-12-16 17:44:58 +0100 | [diff] [blame] | 203 | ret = 0; |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 204 | dont_kill: ; |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 205 | } |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 206 | resume: |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 207 | /* And let them continue */ |
Denys Vlasenko | 1485030 | 2012-04-03 08:16:05 +0200 | [diff] [blame] | 208 | if (signo != SIGSTOP && signo != SIGCONT) |
| 209 | kill(-1, SIGCONT); |
Denis Vlasenko | a0ab943 | 2009-02-07 22:30:39 +0000 | [diff] [blame] | 210 | return ret; |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 213 | /* Pid or name is required for kill/killall */ |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 214 | if (!arg) { |
Denis Vlasenko | 1fe4e9e | 2007-11-15 00:57:40 +0000 | [diff] [blame] | 215 | bb_error_msg("you need to specify whom to kill"); |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 216 | return EXIT_FAILURE; |
| 217 | } |
"Vladimir N. Oleynik" | 1e98a07 | 2006-01-25 13:21:08 +0000 | [diff] [blame] | 218 | |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 219 | if (killall) { |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 220 | /* Looks like they want to do a killall. Do that */ |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 221 | do { |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 222 | pid_t* pidList; |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 223 | |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 224 | pidList = find_pid_by_name(arg); |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 225 | if (*pidList == 0) { |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 226 | errors++; |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 227 | if (!quiet) |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 228 | bb_error_msg("%s: no process killed", arg); |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 229 | } else { |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 230 | pid_t *pl; |
Glenn L McGrath | bb2e9d4 | 2002-11-25 22:12:28 +0000 | [diff] [blame] | 231 | |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 232 | for (pl = pidList; *pl; pl++) { |
| 233 | if (*pl == pid) |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 234 | continue; |
Denis Vlasenko | 35fb512 | 2006-11-01 09:16:49 +0000 | [diff] [blame] | 235 | if (kill(*pl, signo) == 0) |
| 236 | continue; |
| 237 | errors++; |
| 238 | if (!quiet) |
Denys Vlasenko | 651a269 | 2010-03-23 16:25:17 +0100 | [diff] [blame] | 239 | bb_perror_msg("can't kill pid %d", (int)*pl); |
Eric Andersen | 7d72e79 | 2003-07-26 07:41:56 +0000 | [diff] [blame] | 240 | } |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 241 | } |
Eric Andersen | 44608e9 | 2002-10-22 12:21:15 +0000 | [diff] [blame] | 242 | free(pidList); |
Denis Vlasenko | a77947f | 2006-09-27 14:19:16 +0000 | [diff] [blame] | 243 | arg = *++argv; |
Denys Vlasenko | 4b26f82 | 2013-12-16 17:45:44 +0100 | [diff] [blame] | 244 | } while (arg); |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 245 | return errors; |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 246 | } |
Rob Landley | c9c1a41 | 2006-07-12 19:17:55 +0000 | [diff] [blame] | 247 | |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 248 | /* Looks like they want to do a kill. Do that */ |
| 249 | while (arg) { |
Denys Vlasenko | b12553f | 2011-02-21 03:22:20 +0100 | [diff] [blame] | 250 | #if ENABLE_ASH || ENABLE_HUSH |
| 251 | /* |
| 252 | * We need to support shell's "hack formats" of |
| 253 | * " -PRGP_ID" (yes, with a leading space) |
| 254 | * and " PID1 PID2 PID3" (with degenerate case "") |
| 255 | */ |
| 256 | while (*arg != '\0') { |
| 257 | char *end; |
| 258 | if (*arg == ' ') |
| 259 | arg++; |
| 260 | pid = bb_strtoi(arg, &end, 10); |
| 261 | if (errno && (errno != EINVAL || *end != ' ')) { |
| 262 | bb_error_msg("invalid number '%s'", arg); |
| 263 | errors++; |
Alexey Fomenko | 6a93212 | 2011-12-22 11:38:57 +0100 | [diff] [blame] | 264 | break; |
| 265 | } |
| 266 | if (kill(pid, signo) != 0) { |
Denys Vlasenko | b12553f | 2011-02-21 03:22:20 +0100 | [diff] [blame] | 267 | bb_perror_msg("can't kill pid %d", (int)pid); |
| 268 | errors++; |
| 269 | } |
| 270 | arg = end; /* can only point to ' ' or '\0' now */ |
| 271 | } |
| 272 | #else |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 273 | pid = bb_strtoi(arg, NULL, 10); |
| 274 | if (errno) { |
Denys Vlasenko | b32a543 | 2010-08-29 13:29:02 +0200 | [diff] [blame] | 275 | bb_error_msg("invalid number '%s'", arg); |
Denis Vlasenko | f20de5b | 2007-04-29 23:42:54 +0000 | [diff] [blame] | 276 | errors++; |
| 277 | } else if (kill(pid, signo) != 0) { |
Denys Vlasenko | 6331cf0 | 2009-11-13 09:08:27 +0100 | [diff] [blame] | 278 | bb_perror_msg("can't kill pid %d", (int)pid); |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 279 | errors++; |
| 280 | } |
Denys Vlasenko | b12553f | 2011-02-21 03:22:20 +0100 | [diff] [blame] | 281 | #endif |
Denis Vlasenko | 0bb628f | 2006-09-27 14:25:33 +0000 | [diff] [blame] | 282 | arg = *++argv; |
| 283 | } |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 284 | return errors; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 285 | } |