28653a
commit 1c17100c43c0913ec94f3bcc966bf3792236c690
28653a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
28653a
Date:   Tue Mar 24 15:47:13 2020 -0300
28653a
28653a
    support/shell-container.c: Add builtin kill
28653a
    
28653a
    No options supported.
28653a
    
28653a
    Reviewed-by: DJ Delorie <dj@redhat.com>
28653a
28653a
diff --git a/support/shell-container.c b/support/shell-container.c
28653a
index aeaf6d2733abce61..3869e14683fb74dd 100644
28653a
--- a/support/shell-container.c
28653a
+++ b/support/shell-container.c
28653a
@@ -147,6 +147,25 @@ exit_func (char **argv)
28653a
   return 0;
28653a
 }
28653a
 
28653a
+/* Emulate the "/bin/kill" command.  Options are ignored.  */
28653a
+static int
28653a
+kill_func (char **argv)
28653a
+{
28653a
+  int signum = SIGTERM;
28653a
+  int i;
28653a
+
28653a
+  for (i = 0; argv[i]; i++)
28653a
+    {
28653a
+      pid_t pid;
28653a
+      if (strcmp (argv[i], "$$") == 0)
28653a
+	pid = getpid ();
28653a
+      else
28653a
+	pid = atoi (argv[i]);
28653a
+      kill (pid, signum);
28653a
+    }
28653a
+  return 0;
28653a
+}
28653a
+
28653a
 /* This is a list of all the built-in commands we understand.  */
28653a
 static struct {
28653a
   const char *name;
28653a
@@ -156,6 +175,7 @@ static struct {
28653a
   { "echo", echo_func },
28653a
   { "cp", copy_func },
28653a
   { "exit", exit_func },
28653a
+  { "kill", kill_func },
28653a
   { NULL, NULL }
28653a
 };
28653a
 
28653a
@@ -264,6 +284,11 @@ run_command_array (char **argv)
28653a
       if (rv)
28653a
 	exit (rv);
28653a
     }
28653a
+  else if (WIFSIGNALED (status))
28653a
+    {
28653a
+      int sig = WTERMSIG (status);
28653a
+      raise (sig);
28653a
+    }
28653a
   else
28653a
     exit (1);
28653a
 }