diff mbox series

[2/4] support/shell-container.c: Add builtin exit

Message ID 20200324185043.2073568-2-adhemerval.zanella@linaro.org
State Dropped
Headers show
Series [1/4] support/shell-container.c: Return 127 if execve fails | expand

Commit Message

Adhemerval Zanella March 24, 2020, 6:50 p.m. UTC
---
 support/shell-container.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/support/shell-container.c b/support/shell-container.c
index d1112d4009..d405eda60e 100644
--- a/support/shell-container.c
+++ b/support/shell-container.c
@@ -135,6 +135,18 @@  copy_func (char **argv)
 
 }
 
+/* Emulate the "/bin/exit" command.  The exit value is optional.  */
+static int
+exit_func (char **argv)
+{
+  int exit_val = 0;
+
+  if (argv[0] != 0)
+    exit_val = atoi (argv[0]) & 0xff;
+  exit (exit_val);
+  return 0;
+}
+
 /* This is a list of all the built-in commands we understand.  */
 static struct {
   const char *name;
@@ -143,6 +155,7 @@  static struct {
   { "true", true_func },
   { "echo", echo_func },
   { "cp", copy_func },
+  { "exit", exit_func },
   { NULL, NULL }
 };