From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-stable@sourceware.org
Subject: [2.31 COMMITTED] support/shell-container.c: Add builtin kill
Date: Wed, 25 Mar 2020 10:35:49 -0300 [thread overview]
Message-ID: <20200325133550.2530923-3-adhemerval.zanella@linaro.org> (raw)
In-Reply-To: <20200325133550.2530923-1-adhemerval.zanella@linaro.org>
No options supported.
Reviewed-by: DJ Delorie <dj@redhat.com>
(cherry picked from commit 1c17100c43c0913ec94f3bcc966bf3792236c690)
---
support/shell-container.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
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);
}
--
2.17.1
next prev parent reply other threads:[~2020-03-25 13:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 13:35 [2.31 COMMITTED] support/shell-container.c: Return 127 if execve fails Adhemerval Zanella
2020-03-25 13:35 ` [2.31 COMMITTED] support/shell-container.c: Add builtin exit Adhemerval Zanella
2020-03-25 13:35 ` Adhemerval Zanella [this message]
2020-03-25 13:35 ` [2.31 COMMITTED] stdlib: Move tst-system to tests-container Adhemerval Zanella
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200325133550.2530923-3-adhemerval.zanella@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=libc-stable@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).