c5d972
commit 5a5a3a3234bc220a5192d620e0cbc5360da46f14
c5d972
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
c5d972
Date:   Tue Mar 24 15:40:36 2020 -0300
c5d972
c5d972
    support/shell-container.c: Add builtin exit
c5d972
    
c5d972
    Reviewed-by: DJ Delorie <dj@redhat.com>
c5d972
c5d972
diff --git a/support/shell-container.c b/support/shell-container.c
c5d972
index e9eea64bca7e949d..aeaf6d2733abce61 100644
c5d972
--- a/support/shell-container.c
c5d972
+++ b/support/shell-container.c
c5d972
@@ -135,6 +135,18 @@ copy_func (char **argv)
c5d972
 
c5d972
 }
c5d972
 
c5d972
+/* Emulate the 'exit' builtin.  The exit value is optional.  */
c5d972
+static int
c5d972
+exit_func (char **argv)
c5d972
+{
c5d972
+  int exit_val = 0;
c5d972
+
c5d972
+  if (argv[0] != 0)
c5d972
+    exit_val = atoi (argv[0]) & 0xff;
c5d972
+  exit (exit_val);
c5d972
+  return 0;
c5d972
+}
c5d972
+
c5d972
 /* This is a list of all the built-in commands we understand.  */
c5d972
 static struct {
c5d972
   const char *name;
c5d972
@@ -143,6 +155,7 @@ static struct {
c5d972
   { "true", true_func },
c5d972
   { "echo", echo_func },
c5d972
   { "cp", copy_func },
c5d972
+  { "exit", exit_func },
c5d972
   { NULL, NULL }
c5d972
 };
c5d972