Skip to content

Commit 28a0443

Browse files
Attempting to fix global envp
1 parent 8b0d2aa commit 28a0443

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

disk.img

0 Bytes
Binary file not shown.

source/kernel/C/shell/commands/exec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int cmd_exec(int argc, char** argv)
4444
tty_flush_input();
4545
keyboard_flush_buffer();
4646

47-
if (userland_exec(path, user_argc, user_argv, global_envp) != 0) {
47+
if (userland_exec(path, user_argc, user_argv, NULL) != 0) {
4848
keyboard_flush_buffer();
4949
eprintf("exec: failed to load ELF");
5050
return -1;

source/kernel/C/shell/sh.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717

1818
int last_status_code = 0;
1919

20+
static char global_home_env[64] = "HOME=/";
21+
static char global_path_env[256] = "PATH=/";
22+
static char global_term_env[64] = "TERM=linux";
23+
static char global_user_env[64] = "USER=none";
24+
static char global_shlvl_env[32] = "SHLVL=1";
25+
2026
char* global_envp[] = {
21-
"HOME=/",
22-
"PATH=/",
23-
"TERM=linux",
24-
"USER=none",
25-
"SHLVL=1",
27+
global_home_env,
28+
global_path_env,
29+
global_term_env,
30+
global_user_env,
31+
global_shlvl_env,
2632
NULL
2733
};
2834

@@ -171,7 +177,7 @@ void ksh_exec(){
171177
&sudo_flag
172178
};
173179

174-
strcpy(global_envp[3], CONCAT("USER=", username));
180+
snprintf(global_user_env, sizeof(global_user_env), "USER=%s", username);
175181

176182
shell_main(argc, dummy_argv);
177183
}
@@ -225,7 +231,7 @@ int shell_main(int argc, char** argv){
225231
memset(command, 0, commandBufferSize);
226232

227233
if(running){
228-
strcpy(global_envp[1], CONCAT("PATH", vfs_getcwd()));
234+
snprintf(global_path_env, sizeof(global_path_env), "PATH=%s", vfs_getcwd());
229235
show_prompt(argc, argv);
230236
}
231237
continue;

source/kernel/C/userland.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static int string_array_count(const char* const* arr) {
127127
return count;
128128
}
129129

130-
static char* default_envp[] = {
130+
static const char* const default_envp[] = {
131131
"HOME=/",
132132
"PATH=/",
133133
"TERM=linux",

0 commit comments

Comments
 (0)