diff options
author | Elie De Brauwer <eliedebrauwer@gmail.com> | 2012-12-16 13:43:36 +0100 |
---|---|---|
committer | Elie De Brauwer <eliedebrauwer@gmail.com> | 2012-12-16 13:43:36 +0100 |
commit | ca4035bdacfd83f815323c9c597f2683fc4aa218 (patch) | |
tree | b1bc7cdeb58ce9a18efc22cce9fbbe1d186a9f98 /toys/lsb/killall.c | |
parent | a48e5792bb26f95c18055f58d602ac279ebd4002 (diff) | |
download | toybox-ca4035bdacfd83f815323c9c597f2683fc4aa218.tar.gz |
Extend killall with support for -v and -i
Diffstat (limited to 'toys/lsb/killall.c')
-rw-r--r-- | toys/lsb/killall.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/toys/lsb/killall.c b/toys/lsb/killall.c index 2294f61d..655ed734 100644 --- a/toys/lsb/killall.c +++ b/toys/lsb/killall.c @@ -1,20 +1,23 @@ + /* killall.c - Send signal (default: TERM) to all processes with given names. * * Copyright 2012 Andreas Heck <aheck@gmx.de> * * http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/killall.html -USE_KILLALL(NEWTOY(killall, "<1?lq", TOYFLAG_USR|TOYFLAG_BIN)) +USE_KILLALL(NEWTOY(killall, "<1?lqvi", TOYFLAG_USR|TOYFLAG_BIN)) config KILLALL bool "killall" default y help - usage: killall [-l] [-q] [-SIG] PROCESS_NAME... + usage: killall [-l] [-qv] [-SIG] PROCESS_NAME... Send a signal (default: TERM) to all processes with the given names. -l print list of all available signals + -i ask for confirmation before killing + -v report if the signal was successfully sent -q don't print any warnings or error messages */ @@ -25,12 +28,20 @@ GLOBALS( int signum; ) -static int kill_process(pid_t pid) +static int kill_process(pid_t pid, char *name) { int ret; + if(toys.optflags & FLAG_i) { + snprintf(toybuf, sizeof(toybuf), "Signal %s(%d) ?", name, pid); + if (yesno(toybuf, 0) == 0) return 1; + } + toys.exitval = 0; + ret = kill(pid, TT.signum); + if (toys.optflags & FLAG_v) + printf("Killed %s(%d) with signal %d\n", name, pid, TT.signum); if (ret == -1 && !(toys.optflags & FLAG_q)) perror("kill"); return 1; |