]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
support/shell-container.c: Add builtin exit
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Tue, 24 Mar 2020 18:40:36 +0000 (15:40 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 25 Mar 2020 12:50:45 +0000 (09:50 -0300)
Reviewed-by: DJ Delorie <dj@redhat.com>
support/shell-container.c

index d1112d40092836b4972bfd1a05818a1b2db8a9a9..2f7405dc5f4d97775d617058d9cda096f82833ef 100644 (file)
@@ -135,6 +135,18 @@ copy_func (char **argv)
 
 }
 
+/* Emulate the 'exit' builtin.  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 }
 };