summaryrefslogtreecommitdiff
path: root/src/user/test/main.c
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-05-18 16:16:07 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-05-18 16:16:07 +0200
commit7e6454020ed1143e05e83a683606f318995458e5 (patch)
tree763ec6f5dda5f8f662f5eeb38f29d4279681b0a2 /src/user/test/main.c
parentdaa6c2450fa0646619698f0dc01b0456b2541317 (diff)
downloadTCE-7e6454020ed1143e05e83a683606f318995458e5.tar.gz
TCE-7e6454020ed1143e05e83a683606f318995458e5.zip
Can now spawn new processes.
Diffstat (limited to 'src/user/test/main.c')
-rw-r--r--src/user/test/main.c44
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");