Browse Source

Fix debug shell not being able to start a shell by allowing system() in kernel to take an env

K. Lange 5 years ago
parent
commit
864cbdb868
4 changed files with 10 additions and 5 deletions
  1. 1 1
      base/usr/include/kernel/system.h
  2. 1 1
      kernel/main.c
  3. 3 2
      kernel/misc/elf.c
  4. 5 1
      modules/debug_sh.c

+ 1 - 1
base/usr/include/kernel/system.h

@@ -205,7 +205,7 @@ extern void fpu_install(void);
 
 /* ELF */
 extern int exec( char *, int, char **, char **);
-extern int system( char *, int, char **);
+extern int system( char *, int, char **, char **);
 
 /* Sytem Calls */
 extern void syscalls_install(void);

+ 1 - 1
kernel/main.c

@@ -259,7 +259,7 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
 	while (argv[argc]) {
 		argc++;
 	}
-	system(argv[0], argc, argv); /* Run init */
+	system(argv[0], argc, argv, NULL); /* Run init */
 
 	debug_print(CRITICAL, "init failed");
 	switch_task(0);

+ 3 - 2
kernel/misc/elf.c

@@ -303,7 +303,8 @@ int
 system(
 		char *  path, /* Path to the executable to run */
 		int     argc, /* Argument count (ie, /bin/echo hello world = 3) */
-		char ** argv  /* Argument strings (including executable path) */
+		char ** argv, /* Argument strings (including executable path) */
+		char ** envin
 	) {
 	char ** argv_ = malloc(sizeof(char *) * (argc + 1));
 	for (int j = 0; j < argc; ++j) {
@@ -318,7 +319,7 @@ system(
 
 	current_process->cmdline = argv_;
 
-	exec(path,argc,argv_,env);
+	exec(path,argc,argv_,envin ? envin : env);
 	debug_print(ERROR, "Failed to execute process!");
 	kexit(-1);
 	return -1;

+ 5 - 1
modules/debug_sh.c

@@ -116,7 +116,11 @@ static void debug_shell_run_sh(void * data, char * name) {
 	while (argv[argc]) {
 		argc++;
 	}
-	system(argv[0], argc, argv); /* Run shell */
+	char * env[] = {
+		"LD_LIBRARY_PATH=/lib",
+		NULL
+	};
+	system(argv[0], argc, argv, env); /* Run shell */
 
 	task_exit(42);
 }