Mercurial > hg > toybox
changeset 766:5d435b48da8d
LSB does not allow killall to kill itself
author | Elie De Brauwer <eliedebrauwer@gmail.com> |
---|---|
date | Sun, 16 Dec 2012 16:51:30 +0100 |
parents | e2e99fa861e9 |
children | 979d038c1688 |
files | toys/lsb/killall.c |
diffstat | 1 files changed, 5 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/toys/lsb/killall.c Sun Dec 23 14:06:17 2012 -0600 +++ b/toys/lsb/killall.c Sun Dec 16 16:51:30 2012 +0100 @@ -1,4 +1,3 @@ - /* killall.c - Send signal (default: TERM) to all processes with given names. * * Copyright 2012 Andreas Heck <aheck@gmx.de> @@ -26,12 +25,15 @@ GLOBALS( int signum; + pid_t cur_pid; ) static int kill_process(pid_t pid, char *name) { int ret; + if (pid == TT.cur_pid) return 1; + if(toys.optflags & FLAG_i) { snprintf(toybuf, sizeof(toybuf), "Signal %s(%d) ?", name, pid); if (yesno(toybuf, 0) == 0) return 1; @@ -79,6 +81,8 @@ } } + TT.cur_pid = getpid(); + for_each_pid_with_name_in(names, kill_process); if (toys.exitval && !(toys.optflags & FLAG_q)) error_exit("No such process");