diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-02-07 22:30:39 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-02-07 22:30:39 +0000 |
commit | a0ab943492c123690f41b751136e8c9cf261e195 (patch) | |
tree | 6e4a65508c55815f3940597bbcb47d3a6062c4da | |
parent | 2ca84f606453636df6f57e81bc6f1fb70b6d5399 (diff) | |
download | busybox-w32-a0ab943492c123690f41b751136e8c9cf261e195.tar.gz busybox-w32-a0ab943492c123690f41b751136e8c9cf261e195.tar.bz2 busybox-w32-a0ab943492c123690f41b751136e8c9cf261e195.zip |
function old new delta
kill_main 706 884 +178
-rw-r--r-- | include/usage.h | 3 | ||||
-rw-r--r-- | procps/kill.c | 57 |
2 files changed, 50 insertions, 10 deletions
diff --git a/include/usage.h b/include/usage.h index 367da1d3d..52af47e58 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -2123,11 +2123,12 @@ | |||
2123 | "$ killall apache\n" | 2123 | "$ killall apache\n" |
2124 | 2124 | ||
2125 | #define killall5_trivial_usage \ | 2125 | #define killall5_trivial_usage \ |
2126 | "[-l] [-SIG]" | 2126 | "[-l] [-SIG] [-o PID]..." |
2127 | #define killall5_full_usage "\n\n" \ | 2127 | #define killall5_full_usage "\n\n" \ |
2128 | "Send a signal (default is TERM) to all processes outside current session\n" \ | 2128 | "Send a signal (default is TERM) to all processes outside current session\n" \ |
2129 | "\nOptions:" \ | 2129 | "\nOptions:" \ |
2130 | "\n -l List all signal names and numbers" \ | 2130 | "\n -l List all signal names and numbers" \ |
2131 | "\n -o PID Do not signal this PID" \ | ||
2131 | /* "\n -s SIG Yet another way of specifying SIG" */ \ | 2132 | /* "\n -s SIG Yet another way of specifying SIG" */ \ |
2132 | 2133 | ||
2133 | #define klogd_trivial_usage \ | 2134 | #define klogd_trivial_usage \ |
diff --git a/procps/kill.c b/procps/kill.c index 140550018..1f8206986 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -92,11 +92,18 @@ int kill_main(int argc, char **argv) | |||
92 | quiet = 1; | 92 | quiet = 1; |
93 | arg = *++argv; | 93 | arg = *++argv; |
94 | argc--; | 94 | argc--; |
95 | if (argc < 1) bb_show_usage(); | 95 | if (argc < 1) |
96 | if (arg[0] != '-') goto do_it_now; | 96 | bb_show_usage(); |
97 | if (arg[0] != '-') | ||
98 | goto do_it_now; | ||
97 | } | 99 | } |
98 | 100 | ||
99 | arg++; /* skip '-' */ | 101 | arg++; /* skip '-' */ |
102 | |||
103 | /* -o PID? (if present, it always is at the end of command line) */ | ||
104 | if (killall5 && arg[0] == 'o') | ||
105 | goto do_it_now; | ||
106 | |||
100 | if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ | 107 | if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */ |
101 | argc--; | 108 | argc--; |
102 | arg = *++argv; | 109 | arg = *++argv; |
@@ -109,25 +116,57 @@ int kill_main(int argc, char **argv) | |||
109 | arg = *++argv; | 116 | arg = *++argv; |
110 | argc--; | 117 | argc--; |
111 | 118 | ||
112 | do_it_now: | 119 | do_it_now: |
113 | pid = getpid(); | 120 | pid = getpid(); |
114 | 121 | ||
115 | if (killall5) { | 122 | if (killall5) { |
116 | pid_t sid; | 123 | pid_t sid; |
117 | procps_status_t* p = NULL; | 124 | procps_status_t* p = NULL; |
125 | int ret = 0; | ||
118 | 126 | ||
119 | /* Find out our own session id */ | 127 | /* Find out our session id */ |
120 | sid = getsid(pid); | 128 | sid = getsid(pid); |
121 | /* Now stop all processes */ | 129 | /* Stop all processes */ |
122 | kill(-1, SIGSTOP); | 130 | kill(-1, SIGSTOP); |
123 | /* Now kill all processes except our session */ | 131 | /* Signal all processes except those in our session */ |
124 | while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) { | 132 | while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) { |
125 | if (p->sid != (unsigned)sid && p->pid != (unsigned)pid && p->pid != 1) | 133 | int i; |
126 | kill(p->pid, signo); | 134 | |
135 | if (p->sid == (unsigned)sid | ||
136 | || p->pid == (unsigned)pid | ||
137 | || p->pid == 1) | ||
138 | continue; | ||
139 | |||
140 | /* All remaining args must be -o PID options. | ||
141 | * Check p->pid against them. */ | ||
142 | for (i = 0; i < argc; i++) { | ||
143 | pid_t omit; | ||
144 | |||
145 | arg = argv[i]; | ||
146 | if (arg[0] != '-' || arg[1] != 'o') { | ||
147 | bb_error_msg("bad option '%s'", arg); | ||
148 | ret = 1; | ||
149 | goto resume; | ||
150 | } | ||
151 | arg += 2; | ||
152 | if (!arg[0] && argv[++i]) | ||
153 | arg = argv[i]; | ||
154 | omit = bb_strtoi(arg, NULL, 10); | ||
155 | if (errno) { | ||
156 | bb_error_msg("bad pid '%s'", arg); | ||
157 | ret = 1; | ||
158 | goto resume; | ||
159 | } | ||
160 | if (p->pid == omit) | ||
161 | goto dont_kill; | ||
162 | } | ||
163 | kill(p->pid, signo); | ||
164 | dont_kill: ; | ||
127 | } | 165 | } |
166 | resume: | ||
128 | /* And let them continue */ | 167 | /* And let them continue */ |
129 | kill(-1, SIGCONT); | 168 | kill(-1, SIGCONT); |
130 | return 0; | 169 | return ret; |
131 | } | 170 | } |
132 | 171 | ||
133 | /* Pid or name is required for kill/killall */ | 172 | /* Pid or name is required for kill/killall */ |