adding environmental variables support

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@304 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
lillo
2002-07-18 13:59:03 +00:00
parent a4f9f99fb0
commit 0ba337c0a4
17 changed files with 111 additions and 14 deletions
+15
View File
@@ -312,6 +312,7 @@ KernelStaticLibraryObjects libc.a :
<$(SOURCE_GRIST)!libc!stdlib>assert.o
<$(SOURCE_GRIST)!libc!stdlib>atoi.o
<$(SOURCE_GRIST)!libc!stdlib>bsearch.o
<$(SOURCE_GRIST)!libc!stdlib>env.o
<$(SOURCE_GRIST)!libc!stdlib>heapsort.o
<$(SOURCE_GRIST)!libc!stdlib>merge.o
<$(SOURCE_GRIST)!libc!stdlib>multibyte.o
@@ -427,6 +428,7 @@ KernelLd libc.so :
<$(SOURCE_GRIST)!libc!stdlib>assert.o
<$(SOURCE_GRIST)!libc!stdlib>atoi.o
<$(SOURCE_GRIST)!libc!stdlib>bsearch.o
<$(SOURCE_GRIST)!libc!stdlib>env.o
<$(SOURCE_GRIST)!libc!stdlib>heapsort.o
<$(SOURCE_GRIST)!libc!stdlib>merge.o
<$(SOURCE_GRIST)!libc!stdlib>multibyte.o
@@ -698,6 +700,19 @@ KernelLd filetest :
bin/filetest
;
KernelLd envtest :
libglue2.o
<$(SOURCE_GRIST)!apps!envtest>main.o
libc.so
libm.so
:
$(SUBDIR)/ldscripts/$(OBOS_ARCH)/app.ld
:
:
:
bin/envtest
;
KernelLd loop :
<$(SOURCE_GRIST)!add-ons!net!loopback>loop.o
kernel.so
+1
View File
@@ -12,6 +12,7 @@ SubInclude OBOS_TOP src kernel apps mount ;
SubInclude OBOS_TOP src kernel apps ps ;
SubInclude OBOS_TOP src kernel apps rld ;
SubInclude OBOS_TOP src kernel apps shell ;
SubInclude OBOS_TOP src kernel apps envtest ;
#SubInclude OBOS_TOP src kernel apps sockettest ;
SubInclude OBOS_TOP src kernel apps testapp ;
SubInclude OBOS_TOP src kernel apps testdigit ;
+3
View File
@@ -0,0 +1,3 @@
SubDir OBOS_TOP src kernel apps envtest ;
KernelObjects <$(SOURCE_GRIST)>main.c : -fpic -Wno-unused ;
+57
View File
@@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syscalls.h>
int main(int argc, char **argv)
{
int i, rc;
proc_id pid;
char temp[16];
char *var;
printf("Setting some env vars...\n");
if (setenv("TEST", "This is a test!", 0)) {
printf("setenv() error\n");
return -1;
}
if (setenv("HOME", "/boot", 1)) {
printf("setenv() error\n");
return -1;
}
printf("Getting VAR_1: ");
var = getenv("VAR_1");
if (var)
printf("found set to: \"%s\"\n", var);
else
printf("not found\n");
printf("List of env variables set:\n");
for (i=0; environ[i]; i++)
printf("%s\n", environ[i]);
if (argc > 1) {
char buffer[16];
char *_argv[] = { argv[0], buffer, NULL };
int val = atoi(argv[1]) - 1;
sprintf(temp, "VAR_%d", val);
if (setenv(temp, "dummy", 0)) {
printf("setenv() error\n");
return -1;
}
if (val > 0) {
printf("Spawning test (%d left)\n", val);
sprintf(buffer, "%d", val);
pid = sys_proc_create_proc(_argv[0], _argv[0], _argv, 2, NULL, 0, 5);
sys_proc_wait_on_proc(pid, &rc);
}
}
return 0;
}
+2 -2
View File
@@ -50,12 +50,12 @@ main(int argc, char *argv[])
int aaargc= 3;
sprintf(buffer, "%d", num-1);
pid= sys_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, 5);
pid= sys_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, NULL, 0, 5);
sys_proc_wait_on_proc(pid, &retcode);
result= retcode;
sprintf(buffer, "%d", num-2);
pid= sys_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, 5);
pid= sys_proc_create_proc(aaargv[0], aaargv[0], aaargv, aaargc, NULL, 0, 5);
sys_proc_wait_on_proc(pid, &retcode);
result+= retcode;
}
+2 -2
View File
@@ -33,7 +33,7 @@ int main()
if(1) {
proc_id pid;
pid = sys_proc_create_proc("/boot/bin/fortune", "/boot/bin/fortune", NULL, 0, 5);
pid = sys_proc_create_proc("/boot/bin/fortune", "/boot/bin/fortune", NULL, 0, NULL, 0, 5);
if (pid >= 0) {
int retcode;
sys_proc_wait_on_proc(pid, &retcode);
@@ -46,7 +46,7 @@ int main()
while(1) {
proc_id pid;
pid = sys_proc_create_proc("/boot/bin/shell", "/boot/bin/shell", NULL, 0, 5);
pid = sys_proc_create_proc("/boot/bin/shell", "/boot/bin/shell", NULL, 0, NULL, 0, 5);
if(pid >= 0) {
int retcode;
printf("init: spawned shell, pid 0x%x\n", pid);
+1 -1
View File
@@ -65,7 +65,7 @@ int cmd_create_proc(int argc,char *argv[])
}
}
pid = sys_proc_create_proc(filename,filename, argv, argc, 5);
pid = sys_proc_create_proc(filename,filename, argv, argc, NULL, 0, 5);
if(pid >= 0) {
int retcode;
+1 -1
View File
@@ -71,7 +71,7 @@ int exec_file(int argc,char *argv[],int *retcode)
if( !find_file_in_path(argv[0],filename,SCAN_SIZE)) return SHE_FILE_NOT_FOUND;
pid = sys_proc_create_proc(filename,filename, argv, argc, 5);
pid = sys_proc_create_proc(filename,filename, argv, argc, NULL, 0, 5);
if(pid < 0) return SHE_CANT_EXECUTE;
+1 -2
View File
@@ -121,7 +121,6 @@ static int main2(void *unused)
bus_init(&ka);
dev_init(&ka);
con_init(&ka);
//net_init_postdev(&ka);
#if 0
@@ -147,7 +146,7 @@ static int main2(void *unused)
// start the init process
{
proc_id pid;
pid = proc_create_proc("/boot/bin/init", "init", NULL, 0, 5);
pid = proc_create_proc("/boot/bin/init", "init", NULL, 0, NULL, 0, 5);
if(pid < 0)
kprintf("error starting 'init' error = %d \n",pid);
}
+7 -1
View File
@@ -143,7 +143,7 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
*call_ret = 0;
break;
case SYSCALL_PROC_CREATE_PROC:
*call_ret = user_proc_create_proc((const char *)arg0, (const char *)arg1, (char **)arg2, (int )arg3, (int)arg4);
*call_ret = user_proc_create_proc((const char *)arg0, (const char *)arg1, (char **)arg2, (int)arg3, (char **)arg4, (int)arg5, (int)arg6);
break;
case SYSCALL_THREAD_WAIT_ON_THREAD:
*call_ret = user_thread_wait_on_thread((thread_id)arg0, (int *)arg1);
@@ -301,6 +301,12 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
// or just call vfs_getrlimit()
*call_ret = (get_current_io_context(false))->table_size;
break;
case SYSCALL_SETENV:
*call_ret = user_setenv((const char *)arg0, (const char *)arg1, (int)arg2);
break;
case SYSCALL_GETENV:
*call_ret = user_getenv((const char *)arg0, (char **)arg1);
break;
default:
*call_ret = -1;
}