summaryrefslogtreecommitdiff
path: root/kernel/syscalls.c
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-11-24 01:10:32 +0100
committerMichal Idziorek <m.i@gmx.at>2014-11-24 01:10:32 +0100
commit0d36b950f6a560a0312f2dcd326d3bb5362af370 (patch)
tree6d417483e22589e5ca07bf98a0bd8099ae5882e8 /kernel/syscalls.c
parentec0ba7bc40854eab6a1cdb41364f41f9c11407e1 (diff)
playing with enviroment variables
Diffstat (limited to 'kernel/syscalls.c')
-rw-r--r--kernel/syscalls.c61
1 files changed, 56 insertions, 5 deletions
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index e4cb6cc..4023dfe 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -191,6 +191,49 @@ int syscall_execve(char *name, char **argv, char **env)
}
argvcopy[argc]=NULL;
+ //
+ char *env1="PS1=$ ";
+ char *env2="PATH=/bin";
+ char environstr[256];
+ char **oldenviron=env;
+ char **environ=0xf00001;
+
+ static bool first=true;
+ if(first)
+ {
+ environ[0]=env1;
+ environ[1]=env2;
+ environ[3]=NULL;
+ first=false;
+ }
+ else
+ {
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"environ: (0x%08X)",oldenviron);
+ int i=0;
+ 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{
+ j++;
+ k++;
+ environstr[k]=oldenviron[i][j];
+ }while(oldenviron[i][j]!=0);
+
+ environ[i]=&environstr[start];
+ i++;
+ }
+
+ environ[i]=NULL;
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[0],environ[0]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[1],environ[1]);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"duplicate env: %s (0x%08X)",environ[2],environ[2]);
+
+ }
+
+
//TODO: load ELF binary and move this to own compilation unit
@@ -278,10 +321,18 @@ int syscall_execve(char *name, char **argv, char **env)
}
- // argv / argc
- //asm("mov $0xf00000,%esp"); // set stack pointer
+
+ int i=0;
+ do{
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"envvar %d : 0x%08X : %s" ,i,environ[i],environ[i]);
+ i++;
+ }while(environ[i]!=NULL);
+
+
+ asm("mov $0xf00000,%esp"); // set stack pointer
asm("push %0" :: "r" (argvcopy));
asm("push %0" :: "r" (argc));
+ asm("push %0" :: "r" (environ));
// push addr and return to it
asm("push %0"::"r"(elf->e_entry));
@@ -342,14 +393,14 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
}
-int syscall_exit(int ret, int none1, int none2)
+int syscall_exit(int ret, char **env, int none2)
{
#ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d)", ret);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d) (env=0x%08X)", ret, env);
#endif
static char *argv[]={"shell","--silent",NULL};
- syscall_execve("/bin/foolshell",argv,0); // start shell
+ syscall_execve("/bin/foolshell",argv,env); // start shell
}