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