PID -2 to -9 for kill too

Commit 4359cf0698 restored kill's ability
to kill PID -1. This however left PIDs -2 to -9 (or rather process
groups 2 to 9) still having this problem. The check is now generically
looking for a digit and parses it correctly.
This commit is contained in:
Craig Small 2014-01-29 22:28:02 +11:00
parent 5a34ff0a99
commit 39210a89de

16
skill.c
View File

@ -195,7 +195,8 @@ static void check_proc(int pid, struct run_time_conf_t *run_time)
if (i == -1)
goto closure;
}
read(fd, buf, 128);
if (read(fd, buf, 128) <= 0)
goto closure;
buf[127] = '\0';
tmp = strrchr(buf, ')');
*tmp++ = '\0';
@ -477,15 +478,16 @@ static void __attribute__ ((__noreturn__))
display_kill_version();
exit(EXIT_SUCCESS);
case '?':
/* Special case is -1 which means all except init */
if (optopt == '1') {
if (kill(-1, signo) != 0)
exitvalue = EXIT_FAILURE;
exit(exitvalue);
}
if (!isdigit(optopt)) {
xwarnx(_("invalid argument %c"), optopt);
kill_usage(stderr);
} else {
/* Special case for signal digit negative
* PIDs */
pid = (long)('0' - optopt);
if (kill((pid_t)pid, signo) != 0)
exitvalue = EXIT_FAILURE;
exit(exitvalue);
}
loop=0;
break;