diff options
Diffstat (limited to 'src/user/test')
-rw-r--r-- | src/user/test/main.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/user/test/main.c b/src/user/test/main.c index 81753bd..eb289ca 100644 --- a/src/user/test/main.c +++ b/src/user/test/main.c @@ -74,6 +74,19 @@ void list_dir(FILE f, int lv) { } } +void list_root() { + FILE f = open("/", 0); + if (f <= 0) { + printk(" -> Could not open '/', error #"); + printk_int(f); + printk("...\n"); + } else { + printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n"); + list_dir(f, 1); + close(f); + } +} + void fprint(FILE f, char *s) { write(f, 0, strlen(s), s); } @@ -102,19 +115,9 @@ int main(char** args) { if (threads == 0) break; } printk("\n -> Ok, let's try something else.\n"); + list_root(); - FILE f = open("/", 0); - if (f <= 0) { - printk(" -> Could not open '/', error #"); - printk_int(f); - printk("...\n"); - } else { - printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n"); - list_dir(f, 1); - close(f); - } - - f = open("/.ui/klog", 0); + FILE f = open("/.ui/klog", 0); if (f <= 0) { printk(" -> Error #"); printk_int(f); printk(" - too bad. Exiting.\n"); } else { @@ -133,13 +136,26 @@ int main(char** args) { } else if (strcmp(buffer, "help") == 0) { fprint(f, "Available commands: about, help, exit.\n"); } else if (strcmp(buffer, "exit") == 0) { - fprint(f, "Exiting the shell. I think the system is pretty likely to panic.\n"); + fprint(f, "Exiting the shell. See you later!\n"); break; } else if (strcmp(buffer, "gotosleep") == 0) { while (1) thread_sleep(1000); + } else if (strcmp(buffer, "spawn") == 0) { + char *args[] = {"hello", "world", 0}; + int pid = run("/somewhere/bin/test", args); + if (pid < 0) { + printk("Error "); printk_int(pid); printk("\n"); + } else { + printk("Launched, pid="); printk_int(pid); printk("\n"); + int ret = waitpid(pid); + printk("Exited, ret="); printk_int(ret); printk("\n"); + } + } else if (strcmp(buffer, "root") == 0) { + list_root(); } else { - fprint(f, "Unknown command. "); + fprint(f, "Unknown command : "); fprint(f, buffer); + fprint(f, "\n"); } } else { fprint(f, " - - - oops\n"); |