diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/app/shell/builtins.c | 17 | ||||
-rw-r--r-- | src/user/app/shell/shell.c | 9 | ||||
-rw-r--r-- | src/user/app/shell/shell.h | 1 |
3 files changed, 20 insertions, 7 deletions
diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c index 53534ed..2562c18 100644 --- a/src/user/app/shell/builtins.c +++ b/src/user/app/shell/builtins.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <user/lib/fs/misc.h> #define DEFAULT_ARGV(...) \ char *_argv_default[] = {argv[0], __VA_ARGS__}; \ @@ -155,6 +156,21 @@ static void cmd_touch(int argc, char **argv) { } } +static void cmd_whitelist(int argc, char **argv) { + int split = 1; + for (;;) { + if (split >= argc) { + eprintf("no command"); + return; + } + if (!strcmp("--", argv[split])) break; + split++; + } + argv[split] = NULL; + MOUNT_AT("/") { fs_whitelist((void*)&argv[1]); } + run_args(argc - split - 1, &argv[split + 1], NULL); +} + struct builtin builtins[] = { {"cat", cmd_cat}, {"echo", cmd_echo}, @@ -163,5 +179,6 @@ struct builtin builtins[] = { {"ls", cmd_ls}, {"sleep", cmd_sleep}, {"touch", cmd_touch}, + {"whitelist", cmd_whitelist}, {NULL, NULL}, }; diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c index 505997a..6083578 100644 --- a/src/user/app/shell/shell.c +++ b/src/user/app/shell/shell.c @@ -33,7 +33,7 @@ static void execp(char **argv) { free(s); } -static void run_args(int argc, char **argv, struct redir *redir) { +void run_args(int argc, char **argv, struct redir *redir) { if (!*argv) return; /* "special" commands that can't be handled in a subprocess */ @@ -41,11 +41,6 @@ static void run_args(int argc, char **argv, struct redir *redir) { // TODO process groups _syscall_mount(-1, argv[1], strlen(argv[1])); return; - } else if (!strcmp(argv[0], "whitelist")) { - MOUNT_AT("/") { - fs_whitelist((void*)&argv[1]); - } - return; } else if (!strcmp(argv[0], "time")) { uint64_t time = __rdtsc(); uint64_t div = 3000; @@ -62,7 +57,7 @@ static void run_args(int argc, char **argv, struct redir *redir) { return; } - if (redir->stdout) { + if (redir && redir->stdout) { FILE *f = fopen(redir->stdout, redir->append ? "a" : "w"); if (!f) { eprintf("couldn't open %s for redirection", redir->stdout); diff --git a/src/user/app/shell/shell.h b/src/user/app/shell/shell.h index 5097e00..a8f0012 100644 --- a/src/user/app/shell/shell.h +++ b/src/user/app/shell/shell.h @@ -10,3 +10,4 @@ struct redir { }; int parse(char *s, char **argv, size_t argvlen, struct redir *redir); +void run_args(int argc, char **argv, struct redir *redir); |