aboutsummaryrefslogtreecommitdiff
path: root/libbb/setup_environment.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-10 13:15:28 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-10 13:15:28 +0000
commita2f61012b6f93473ed002e6609557cb1cd81b7dd (patch)
tree51ce422afbda2249a5de22e834ed04e200e0961f /libbb/setup_environment.c
parentac074b3f87cc22c2ddadb074d630156fea720744 (diff)
downloadbusybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.tar.gz
busybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.tar.bz2
busybox-w32-a2f61012b6f93473ed002e6609557cb1cd81b7dd.zip
setup_environment: code shrink
run_shell: mark as NORETURN setup_environment, run_shell: add usage comments login: add FIXME :( function old new delta UNSPEC_print 64 66 +2 sulogin_main 509 506 -3 mkfs_minix_main 3070 3067 -3 login_main 1615 1612 -3 su_main 461 448 -13 setup_environment 261 206 -55 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/5 up/down: 2/-77) Total: -75 bytes text data bss dec hex filename 772578 1051 10724 784353 bf7e1 busybox_old 772502 1051 10724 784277 bf795 busybox_unstripped
Diffstat (limited to 'libbb/setup_environment.c')
-rw-r--r--libbb/setup_environment.c25
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}