diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-12-02 01:02:49 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-12-02 01:02:49 +0100 |
| commit | c2c03f41e078481921bad82487eded0fc51ebb59 (patch) | |
| tree | 1e310556c9a809aea112728bae9e0a6807ee0ba2 /userspace | |
| parent | f20db37ca17245d5d20302a1ac1da347de5c3607 (diff) | |
further work on fork and friends
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/foolshell.c | 13 | ||||
| -rw-r--r-- | userspace/init.c | 15 |
2 files changed, 19 insertions, 9 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 78ba327..7d2291e 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -109,7 +109,7 @@ int process(char *buf) if(!strcmp(command,"help")) { - puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv/setenv [var] [val]', 'env' 'cd [dir]'"); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv/setenv [var] [val]', 'env' 'cd [dir]', 'exit'"); } else if(!strcmp(command,"cd")) { @@ -173,6 +173,11 @@ int process(char *buf) setenv("PWD",buf,1); } + else if(!strcmp(command,"exit")) + { + exit(1); + + } else if(!strcmp(command,"echo")) { printf("\"%s\"\n",token[1]); @@ -215,12 +220,18 @@ int process(char *buf) if(pid!=0) { printf("new task pid: %i \n",pid); + } + if(pid==0) + { char buf[256]; sprintf(buf,"%s/%s",getenv("PATH"),token[0]); + sprintf(buf,"%s/%s","/bin",token[0]); execve(buf,token,environ); puts("foolshell: command not found"); exit(1); } + int status; + wait(&status); } return 0; diff --git a/userspace/init.c b/userspace/init.c index fd562a9..8c3bcd7 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,21 +1,20 @@ + int main(int argc, char **argv) { int pid=fork(); - if(pid!=0) + if(pid==0) { - printf("fool-init: forked child (pid: %i) spawning a Fools Shell\n",pid); execve("/bin/foolshell",0,0); - } else { - // TODO: wait for child and respawn shell if needed! - volatile int i=0; - while(1) - { + printf("fool-init: forked child (pid: %i) spawning a Fools Shell\n",pid); + int status; + int pid_ret=wait(&status); + puts("child state has changed!"); + execve("/bin/init",0,0); - } } return 0; } |
