summaryrefslogtreecommitdiff
path: root/userspace/foolshell.c
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/foolshell.c')
-rw-r--r--userspace/foolshell.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 984cc4f..3c1fb50 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -52,15 +52,9 @@ void prompt()
int main(int argc, char **argv)
{
-/*
- printf("_impure_ptr: 0x%08x\n",_impure_ptr);
- printf("argv= 0x%08x \n",argv);
- printf("environ= 0x%08x \n",environ);
-*/
bool silent=false;
for(int i=0;i<argc;i++)
{
-// printf("%i:%s\n",i+1,argv[i]);
if(!strcmp(argv[i],"--silent"))silent=true;
}
@@ -69,6 +63,7 @@ int main(int argc, char **argv)
char *buf=calloc(sizeof(char),256);
setvbuf(stdin,NULL,_IONBF,0);
+ setvbuf(stdout,NULL,_IONBF,0);
while(1)
{
@@ -217,12 +212,10 @@ int process(char *buf)
// printf("adjusted: '%s'\n",buf);
if(buf[0]==0)setenv("PWD","/",1);
else setenv("PWD",buf,1);
-
}
else if(!strcmp(command,"exit"))
{
- exit(1);
-
+ _exit(1);
}
else if(!strcmp(command,"echo"))
{
@@ -253,23 +246,18 @@ int process(char *buf)
else
{
int pid=_fork();
- if(pid!=0)
- {
- // printf("new task pid: %i \n",pid);
- }
+
if(pid==0)
{
- char buf[256];
sprintf(buf,"%s",token[0]);
_execve(buf,token,environ);
- //sprintf(buf,"%s/%s",getenv("PATH"),token[0]);
- sprintf(buf,"%s/%s","/bin",token[0]);
+ sprintf(buf,"%s/%s",getenv("PATH"),token[0]);
_execve(buf,token,environ);
puts("foolshell: command not found");
- exit(1);
+ exit(0);
}
- int status;
- if(strcmp(token[1],"branch"))_wait(&status);
+
+ if(token[1]!=NULL&&strcmp(token[1],"branch"))_wait(pid);
}
return 0;