diff options
author | Rob Landley <rob@landley.net> | 2014-07-06 19:14:05 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-07-06 19:14:05 -0500 |
commit | ffa7e3b05eea2d404758758c561f534824ca77c8 (patch) | |
tree | 63c9625f690df940215b22997b8deb1e990c90b4 /toys/pending/killall5.c | |
parent | 36f6dea7ea3c9973910f38af61a58f20513b95c8 (diff) | |
download | toybox-ffa7e3b05eea2d404758758c561f534824ca77c8.tar.gz |
Promote killall5 by merging it into kill.
Slight conflict here: this puts killall5 in the posix directory. But the commands sharing code trumps that.
Diffstat (limited to 'toys/pending/killall5.c')
-rw-r--r-- | toys/pending/killall5.c | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/toys/pending/killall5.c b/toys/pending/killall5.c deleted file mode 100644 index 4d9dadce..00000000 --- a/toys/pending/killall5.c +++ /dev/null @@ -1,97 +0,0 @@ -/* killall5.c - Send signal (default: TERM) to all processes outside current session. - * - * Copyright 2014 Ranjan Kumar <ranjankumar.bth@gmail.com> - * Copyright 2014 Kyungwan Han <asura321@gamil.com> - * - * No Standard - -USE_KILLALL5(NEWTOY(killall5, "?o*ls:[!lo]", TOYFLAG_SBIN)) - -config KILLALL5 - bool "killall5" - default n - help - usage: killall5 [-l] [-SIGNAL|-s SIGNAL] [-o PID]... - - Send a signal (default: TERM) to all processes outside current session. - - -l List all signal names and numbers - -o PID Don't signal this PID - -s send SIGNAL instead of SIGTERM -*/ -#define FOR_killall5 -#include "toys.h" - -GLOBALS( - char *signame; - struct arg_list *olist; -) - -void killall5_main(void) -{ - DIR *dp; - struct dirent *entry; - int signo, pid, sid, signum = SIGTERM; - long *olist = NULL, ocount = 0; - char *s, **args = toys.optargs; - - // list all signal names and numbers - if (toys.optflags & FLAG_l) { - if (*args) { - for (; *args; args++) { - signo = sig_to_num(*args); - if (isdigit(**args) && (s = num_to_sig(signo&127))) xputs(s); - else if (signo > 0) xprintf("%d\n", signo); - else error_exit("UNKNOWN signal '%s'", *args); - } - } else sig_to_num(NULL); - return; - } - - // when SIGNUM will be in the form of -SIGNUM - if (TT.signame || (*args && **args == '-')) { - if (0 > (signum = sig_to_num(TT.signame ? TT.signame : (*args)+1))) - error_exit("Unknown signal '%s'", *args); - if (!TT.signame) args++; - } - pid = getpid(); - sid = getsid(pid); - - // prepare omit list - if (toys.optflags & FLAG_o) { - struct arg_list *ptr = TT.olist; - - if (*args) error_exit("invalid omit list"); - for (; ptr; ptr=ptr->next) { - long val = atolx(ptr->arg); - olist = xrealloc(olist, (ocount+1)*sizeof(long)); - olist[ocount++] = val; - } - } - - if (!(dp = opendir("/proc"))) perror_exit("opendir"); - while ((entry = readdir(dp))) { - int count, procpid, procsid; - - if (!(procpid = atoi(entry->d_name))) continue; - snprintf(toybuf, sizeof(toybuf), "/proc/%d/stat", procpid); - if (!readfile(toybuf, toybuf, sizeof(toybuf))) continue; - if (sscanf(toybuf, "%*d %*s %*c %*d %*d %d", &procsid) != 1) continue; - if (pid == procpid || sid == procsid || procpid == 1) continue; - - // Check for kernel threads. - snprintf(toybuf, sizeof(toybuf), "/proc/%d/cmdline", procpid); - if (readfile(toybuf, toybuf, sizeof(toybuf)) && !*toybuf) continue; - - // Check with omit list. - if (toys.optflags & FLAG_o) { - for (count = 0; count < ocount; count++) { - if (procpid == olist[count]) goto OMIT; - } - } - kill(procpid, signum); -OMIT: ; - } - closedir(dp); - if (CFG_TOYBOX_FREE && olist) free(olist); -} |