diff options
author | 2020-03-24 15:47:13 -0300 | |
---|---|---|
committer | 2020-04-12 00:52:33 +0300 | |
commit | 84f611babe6f4d34465eec2b23f258138f747aa6 (patch) | |
tree | cadc775e7664e82143040269213d56b3e03a4b27 | |
parent | support/shell-container.c: Add builtin exit (diff) | |
download | glibc-84f611babe6f4d34465eec2b23f258138f747aa6.tar.gz glibc-84f611babe6f4d34465eec2b23f258138f747aa6.tar.bz2 glibc-84f611babe6f4d34465eec2b23f258138f747aa6.zip |
support/shell-container.c: Add builtin kill
No options supported.
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 1c17100c43c0913ec94f3bcc966bf3792236c690)
(cherry picked from commit ad9b0037ccc588804ef4c5e58feeab370543cf5a)
-rw-r--r-- | support/shell-container.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/support/shell-container.c b/support/shell-container.c index 6540f8ac47..201536d24e 100644 --- a/support/shell-container.c +++ b/support/shell-container.c @@ -147,6 +147,25 @@ exit_func (char **argv) return 0; } +/* Emulate the "/bin/kill" command. Options are ignored. */ +static int +kill_func (char **argv) +{ + int signum = SIGTERM; + int i; + + for (i = 0; argv[i]; i++) + { + pid_t pid; + if (strcmp (argv[i], "$$") == 0) + pid = getpid (); + else + pid = atoi (argv[i]); + kill (pid, signum); + } + return 0; +} + /* This is a list of all the built-in commands we understand. */ static struct { const char *name; @@ -156,6 +175,7 @@ static struct { { "echo", echo_func }, { "cp", copy_func }, { "exit", exit_func }, + { "kill", kill_func }, { NULL, NULL } }; @@ -264,6 +284,11 @@ run_command_array (char **argv) if (rv) exit (rv); } + else if (WIFSIGNALED (status)) + { + int sig = WTERMSIG (status); + raise (sig); + } else exit (1); } |