summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
Diffstat (limited to 'userspace')
-rw-r--r--userspace/foolshell.c13
-rw-r--r--userspace/init.c15
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;
}