summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-09 21:00:44 +0100
committerAnton Kling <anton@kling.gg>2024-12-09 21:00:44 +0100
commit0d2f1ff5ca366f9ba18a349f5e06295f264c5da4 (patch)
tree9951e75885f7970c6a1dbe976454390419df8ab7
parent635f756fa91e22f6c4fd653e5ed2a808eb7335ae (diff)
sh: Add exit command
-rw-r--r--userland/minibox/utilities/sh/sh.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c
index e129044..b00b440 100644
--- a/userland/minibox/utilities/sh/sh.c
+++ b/userland/minibox/utilities/sh/sh.c
@@ -1,5 +1,6 @@
#include "ast.h"
#include "lexer.h"
+#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
@@ -106,6 +107,22 @@ int execute_command(struct AST *ast, int input_fd) {
return 1;
}
return 0;
+ } else if (sv_eq(program, C_TO_SV("exit"))) {
+ uint64_t rc = 0;
+ struct AST *child = ast->children;
+ if (child) {
+ struct sv rest;
+ rc = sv_parse_unsigned_number(child->val.string, &rest);
+ if (rc > 255) {
+ rc = 2;
+ }
+ if (!sv_isempty(rest)) {
+ rc = 2;
+ }
+ }
+ exit(rc);
+ assert(0);
+ return 0;
}
return execute_binary(ast, input_fd);
}