Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/libbb/setup_environment.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/libbb/setup_environment.c
r1765 r2725 31 31 #include "libbb.h" 32 32 33 void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw)33 void FAST_FUNC setup_environment(const char *shell, int flags, const struct passwd *pw) 34 34 { 35 if (loginshell) { 35 /* Change the current working directory to be the home directory 36 * of the user */ 37 if (chdir(pw->pw_dir)) { 38 xchdir((flags & SETUP_ENV_TO_TMP) ? "/tmp" : "/"); 39 bb_error_msg("can't chdir to home directory '%s'", pw->pw_dir); 40 } 41 42 if (flags & SETUP_ENV_CLEARENV) { 36 43 const char *term; 37 44 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 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)) { 45 xchdir("/"); 46 fputs("warning: cannot change to home directory\n", stderr); 47 } 48 49 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 50 Unset all other environment variables. */ 45 /* Leave TERM unchanged. Set HOME, SHELL, USER, LOGNAME, PATH. 46 * Unset all other environment variables. */ 51 47 term = getenv("TERM"); 52 48 clearenv(); 53 49 if (term) 54 50 xsetenv("TERM", term); 55 xsetenv("HOME", pw->pw_dir); 56 xsetenv("SHELL", shell); 57 xsetenv("USER", pw->pw_name); 58 xsetenv("LOGNAME", pw->pw_name); 59 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); 60 } 61 else if (changeenv) { 51 xsetenv("PATH", (pw->pw_uid ? bb_default_path : bb_default_root_path)); 52 goto shortcut; 53 // No, gcc (4.2.1) is not clever enougn to do it itself. 54 //xsetenv("USER", pw->pw_name); 55 //xsetenv("LOGNAME", pw->pw_name); 56 //xsetenv("HOME", pw->pw_dir); 57 //xsetenv("SHELL", shell); 58 } else if (flags & SETUP_ENV_CHANGEENV) { 62 59 /* Set HOME, SHELL, and if not becoming a super-user, 63 USER and LOGNAME. */ 64 xsetenv("HOME", pw->pw_dir); 65 xsetenv("SHELL", shell); 60 * USER and LOGNAME. */ 66 61 if (pw->pw_uid) { 62 shortcut: 67 63 xsetenv("USER", pw->pw_name); 68 64 xsetenv("LOGNAME", pw->pw_name); 69 65 } 66 xsetenv("HOME", pw->pw_dir); 67 xsetenv("SHELL", shell); 70 68 } 71 69 }
Note:
See TracChangeset
for help on using the changeset viewer.