diff options
Diffstat (limited to 'libbb/setup_environment.c')
-rw-r--r-- | libbb/setup_environment.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index a6f44f7f0..19a2c6db5 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -36,36 +36,35 @@ void setup_environment(const char *shell, int loginshell, int changeenv, const s | |||
36 | const char *term; | 36 | const char *term; |
37 | 37 | ||
38 | /* Change the current working directory to be the home directory | 38 | /* Change the current working directory to be the home directory |
39 | * of the user. It is a fatal error for this process to be unable | 39 | * of the user */ |
40 | * to change to that directory. There is no "default" home | ||
41 | * directory. | ||
42 | * Some systems default to HOME=/ | ||
43 | */ | ||
44 | if (chdir(pw->pw_dir)) { | 40 | if (chdir(pw->pw_dir)) { |
45 | xchdir("/"); | 41 | xchdir("/"); |
46 | fputs("warning: cannot change to home directory\n", stderr); | 42 | fputs("warning: cannot change to home directory\n", stderr); |
47 | } | 43 | } |
48 | 44 | ||
49 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. | 45 | /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. |
50 | Unset all other environment variables. */ | 46 | Unset all other environment variables. */ |
51 | term = getenv("TERM"); | 47 | term = getenv("TERM"); |
52 | clearenv(); | 48 | clearenv(); |
53 | if (term) | 49 | if (term) |
54 | xsetenv("TERM", term); | 50 | xsetenv("TERM", term); |
55 | xsetenv("HOME", pw->pw_dir); | 51 | xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); |
56 | xsetenv("SHELL", shell); | 52 | goto shortcut; |
57 | xsetenv("USER", pw->pw_name); | 53 | // No, gcc (4.2.1) is not clever enougn to do it itself. |
58 | xsetenv("LOGNAME", pw->pw_name); | 54 | //xsetenv("USER", pw->pw_name); |
59 | xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); | 55 | //xsetenv("LOGNAME", pw->pw_name); |
56 | //xsetenv("HOME", pw->pw_dir); | ||
57 | //xsetenv("SHELL", shell); | ||
60 | } | 58 | } |
61 | else if (changeenv) { | 59 | else if (changeenv) { |
62 | /* Set HOME, SHELL, and if not becoming a super-user, | 60 | /* Set HOME, SHELL, and if not becoming a super-user, |
63 | USER and LOGNAME. */ | 61 | USER and LOGNAME. */ |
64 | xsetenv("HOME", pw->pw_dir); | ||
65 | xsetenv("SHELL", shell); | ||
66 | if (pw->pw_uid) { | 62 | if (pw->pw_uid) { |
63 | shortcut: | ||
67 | xsetenv("USER", pw->pw_name); | 64 | xsetenv("USER", pw->pw_name); |
68 | xsetenv("LOGNAME", pw->pw_name); | 65 | xsetenv("LOGNAME", pw->pw_name); |
69 | } | 66 | } |
67 | xsetenv("HOME", pw->pw_dir); | ||
68 | xsetenv("SHELL", shell); | ||
70 | } | 69 | } |
71 | } | 70 | } |