summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--procps/Kbuild.src3
-rw-r--r--procps/kill.c46
2 files changed, 28 insertions, 21 deletions
diff --git a/procps/Kbuild.src b/procps/Kbuild.src
index dedef88..6b4fb74 100644
--- a/procps/Kbuild.src
+++ b/procps/Kbuild.src
@@ -7,6 +7,3 @@
lib-y:=
INSERT
-
-lib-$(CONFIG_ASH_JOB_CONTROL) += kill.o # used for built-in kill by ash
-lib-$(CONFIG_HUSH_KILL) += kill.o # used for built-in kill by hush
diff --git a/procps/kill.c b/procps/kill.c
index 7c08225..0ef1716 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -92,28 +92,34 @@
* This is needed to avoid collision with kill -9 ... syntax
*/
+//kbuild:lib-$(CONFIG_ASH_JOB_CONTROL) += kill.o
+//kbuild:lib-$(CONFIG_HUSH_KILL) += kill.o
+
+#define SH_KILL (ENABLE_ASH_JOB_CONTROL || ENABLE_HUSH_KILL)
+/* If shells want to have "kill", for ifdefs it's like ENABLE_KILL=1 */
+#if SH_KILL
+# undef ENABLE_KILL
+# define ENABLE_KILL 1
+#endif
+#define KILL_APPLET_CNT (ENABLE_KILL + ENABLE_KILLALL + ENABLE_KILLALL5)
+
int kill_main(int argc UNUSED_PARAM, char **argv)
{
char *arg;
pid_t pid;
int signo = SIGTERM, errors = 0, quiet = 0;
-#if ENABLE_KILL && !ENABLE_KILLALL && !ENABLE_KILLALL5
-# define killall 0
-# define killall5 0
-#elif !ENABLE_KILL && ENABLE_KILLALL && !ENABLE_KILLALL5
-# define killall 1
-# define killall5 0
-#elif !ENABLE_KILL && !ENABLE_KILLALL && ENABLE_KILLALL5
-# define killall 0
-# define killall5 1
+
+#if KILL_APPLET_CNT == 1
+# define is_killall ENABLE_KILLALL
+# define is_killall5 ENABLE_KILLALL5
#else
/* How to determine who we are? find 3rd char from the end:
* kill, killall, killall5
* ^i ^a ^l - it's unique
* (checking from the start is complicated by /bin/kill... case) */
const char char3 = argv[0][strlen(argv[0]) - 3];
-# define killall (ENABLE_KILLALL && char3 == 'a')
-# define killall5 (ENABLE_KILLALL5 && char3 == 'l')
+# define is_killall (ENABLE_KILLALL && char3 == 'a')
+# define is_killall5 (ENABLE_KILLALL5 && char3 == 'l')
#endif
/* Parse any options */
@@ -162,7 +168,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
}
/* The -q quiet option */
- if (killall && arg[1] == 'q' && arg[2] == '\0') {
+ if (is_killall && arg[1] == 'q' && arg[2] == '\0') {
quiet = 1;
arg = *++argv;
if (!arg)
@@ -174,7 +180,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
arg++; /* skip '-' */
/* -o PID? (if present, it always is at the end of command line) */
- if (killall5 && arg[0] == 'o')
+ if (is_killall5 && arg[0] == 'o')
goto do_it_now;
if (argv[1] && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
@@ -190,7 +196,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
do_it_now:
pid = getpid();
- if (killall5) {
+ if (is_killall5) {
pid_t sid;
procps_status_t* p = NULL;
/* compat: exitcode 2 is "no one was signaled" */
@@ -248,13 +254,14 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
return ret;
}
+#if ENABLE_KILL || ENABLE_KILLALL
/* Pid or name is required for kill/killall */
if (!arg) {
bb_error_msg("you need to specify whom to kill");
return EXIT_FAILURE;
}
- if (killall) {
+ if (!ENABLE_KILL || is_killall) {
/* Looks like they want to do a killall. Do that */
do {
pid_t* pidList;
@@ -282,10 +289,12 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
} while (arg);
return errors;
}
+#endif
+#if ENABLE_KILL
/* Looks like they want to do a kill. Do that */
while (arg) {
-#if ENABLE_ASH_JOB_CONTROL || ENABLE_HUSH_KILL
+# if SH_KILL
/*
* We need to support shell's "hack formats" of
* " -PRGP_ID" (yes, with a leading space)
@@ -307,7 +316,7 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
}
arg = end; /* can only point to ' ' or '\0' now */
}
-#else
+# else /* ENABLE_KILL but !SH_KILL */
pid = bb_strtoi(arg, NULL, 10);
if (errno) {
bb_error_msg("invalid number '%s'", arg);
@@ -316,8 +325,9 @@ int kill_main(int argc UNUSED_PARAM, char **argv)
bb_perror_msg("can't kill pid %d", (int)pid);
errors++;
}
-#endif
+# endif
arg = *++argv;
}
return errors;
+#endif
}