]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
support/shell-container.c: Add builtin kill
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 24 Mar 2020 18:47:13 +0000 (15:47 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 25 Mar 2020 12:50:45 +0000 (09:50 -0300)
No options supported.

Reviewed-by: DJ Delorie <dj@redhat.com>
support/shell-container.c

index 2f7405dc5f4d97775d617058d9cda096f82833ef..fb54d8855169a3c6f397dca831506702445aab3d 100644 (file)
@@ -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);
 }