From 48abbcee80a5066159b8ffee5602728dd45b94e4 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Mon, 24 Nov 2014 02:54:32 +0100 Subject: fixed ENV problem --- kernel/syscalls.c | 21 ++++++++++----------- userspace/clear.c | 2 +- userspace/foolshell.c | 12 +++++++++++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/kernel/syscalls.c b/kernel/syscalls.c index b5422c5..941a8e3 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -199,13 +199,11 @@ int syscall_execve(char *name, char **argv, char **env) char **oldenviron=env; char **environ=0xf00001; - static bool first=true; - if(first) + if(oldenviron==0) { environ[0]=env1; environ[1]=env2; - environ[3]=NULL; - first=false; + environ[2]=NULL; } else { @@ -214,17 +212,17 @@ int syscall_execve(char *name, char **argv, char **env) int k=-1; while(oldenviron[i]!=NULL) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy env: %s (0x%08X)",oldenviron[i],oldenviron[i]); - int start=k+1; - int j=-1; - do{ + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy env: %s (0x%08X)",oldenviron[i],oldenviron[i]); + int start=k+1; + int j=-1; + do{ j++; k++; environstr[k]=oldenviron[i][j]; - }while(oldenviron[i][j]!=0); + }while(oldenviron[i][j]!=0); - environ[i]=&environstr[start]; - i++; + environ[i]=&environstr[start]; + i++; } environ[i]=NULL; @@ -392,6 +390,7 @@ uint32_t syscall_sbrk(int incr, int none1, int none2) int syscall_exit(int ret, char **env, int none2) { + asm("mov $0x07bff,%esp"); // set stack pointer #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d) (env=0x%08X)", ret, env); #endif diff --git a/userspace/clear.c b/userspace/clear.c index ab0eb51..09913c3 100644 --- a/userspace/clear.c +++ b/userspace/clear.c @@ -2,7 +2,7 @@ int main() { for(int i=0;i<24;i++) { - puts(); + puts(""); } return 0; diff --git a/userspace/foolshell.c b/userspace/foolshell.c index 9002269..2a70940 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -105,7 +105,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 [var] [val]'"); + puts("foolshell: supported built-in commands: 'help', 'echo [string]', 'malloc [bytes]', 'free [address]', 'getenv [var]', 'putenv [var] [val]', 'env'"); } else if(!strcmp(command,"echo")) { @@ -133,6 +133,16 @@ int process(char *buf) putenv(buf); printf("(0x%08X) set: %s = %s \n",environ,token[1],getenv(token[1])); } + else if(!strcmp(command,"env")) + { + int i=0; + printf("env: 0x%08X\n",environ); + while(environ[i]!=NULL) + { + printf("envvar %s (0x%08X)\n" ,environ[i],environ[i]); + i++; + } + } else { execve(token[0],token,0); -- cgit v1.2.3