diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-20 16:28:59 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-20 16:28:59 +0000 |
commit | b8d1a4cd5f686ee95f6cf13634cba1f96e382f26 (patch) | |
tree | 86423f82c3593245aedae65e2e4c8f7e0c4d6482 | |
parent | b61dc1c1cea7aaef3cd2aa016a9c7d4d1ffd71bf (diff) | |
download | busybox-w32-b8d1a4cd5f686ee95f6cf13634cba1f96e382f26.tar.gz busybox-w32-b8d1a4cd5f686ee95f6cf13634cba1f96e382f26.tar.bz2 busybox-w32-b8d1a4cd5f686ee95f6cf13634cba1f96e382f26.zip |
init: set stderr to NONBLOCK
*: s/setenv(a,b,1)/xsetenv(a,b)/
function old new delta
init_main 856 895 +39
message 146 144 -2
crond_main 1418 1416 -2
run 661 658 -3
zcip_main 1409 1403 -6
edit_file 910 901 -9
environment 20 - -20
-rw-r--r-- | init/init.c | 33 | ||||
-rw-r--r-- | miscutils/crond.c | 6 | ||||
-rw-r--r-- | miscutils/crontab.c | 6 | ||||
-rw-r--r-- | networking/zcip.c | 4 |
4 files changed, 22 insertions, 27 deletions
diff --git a/init/init.c b/init/init.c index e02773cc0..e00a3b128 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -77,14 +77,6 @@ enum { | |||
77 | #endif | 77 | #endif |
78 | }; | 78 | }; |
79 | 79 | ||
80 | static const char *const environment[] = { | ||
81 | "HOME=/", | ||
82 | bb_PATH_root_path, | ||
83 | "SHELL=/bin/sh", | ||
84 | "USER=root", | ||
85 | NULL | ||
86 | }; | ||
87 | |||
88 | /* Function prototypes */ | 80 | /* Function prototypes */ |
89 | static void halt_reboot_pwoff(int sig) NORETURN; | 81 | static void halt_reboot_pwoff(int sig) NORETURN; |
90 | 82 | ||
@@ -118,15 +110,16 @@ static void message(int where, const char *fmt, ...) | |||
118 | { | 110 | { |
119 | static int log_fd = -1; | 111 | static int log_fd = -1; |
120 | va_list arguments; | 112 | va_list arguments; |
121 | int l; | 113 | unsigned l; |
122 | char msg[128]; | 114 | char msg[128]; |
123 | 115 | ||
124 | msg[0] = '\r'; | 116 | msg[0] = '\r'; |
125 | va_start(arguments, fmt); | 117 | va_start(arguments, fmt); |
126 | vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); | 118 | l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments); |
119 | if (l > sizeof(msg) - 2) | ||
120 | l = sizeof(msg) - 2; | ||
121 | msg[l] = '\0'; | ||
127 | va_end(arguments); | 122 | va_end(arguments); |
128 | msg[sizeof(msg) - 2] = '\0'; | ||
129 | l = strlen(msg); | ||
130 | 123 | ||
131 | if (ENABLE_FEATURE_INIT_SYSLOG) { | 124 | if (ENABLE_FEATURE_INIT_SYSLOG) { |
132 | /* Log the message to syslogd */ | 125 | /* Log the message to syslogd */ |
@@ -213,6 +206,8 @@ static void console_init(void) | |||
213 | /* Make sure fd 0,1,2 are not closed | 206 | /* Make sure fd 0,1,2 are not closed |
214 | * (so that they won't be used by future opens) */ | 207 | * (so that they won't be used by future opens) */ |
215 | bb_sanitize_stdio(); | 208 | bb_sanitize_stdio(); |
209 | /* Make sure init can't be blocked by writing to stderr */ | ||
210 | fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK); | ||
216 | } | 211 | } |
217 | 212 | ||
218 | s = getenv("TERM"); | 213 | s = getenv("TERM"); |
@@ -825,15 +820,15 @@ int init_main(int argc UNUSED_PARAM, char **argv) | |||
825 | set_sane_term(); | 820 | set_sane_term(); |
826 | xchdir("/"); | 821 | xchdir("/"); |
827 | setsid(); | 822 | setsid(); |
828 | { | 823 | |
829 | const char *const *e; | 824 | /* Make sure environs is set to something sane */ |
830 | /* Make sure environs is set to something sane */ | 825 | putenv((char *) "HOME=/"); |
831 | for (e = environment; *e; e++) | 826 | putenv((char *) bb_PATH_root_path); |
832 | putenv((char *) *e); | 827 | putenv((char *) "SHELL=/bin/sh"); |
833 | } | 828 | putenv((char *) "USER=root"); /* needed? why? */ |
834 | 829 | ||
835 | if (argv[1]) | 830 | if (argv[1]) |
836 | setenv("RUNLEVEL", argv[1], 1); | 831 | xsetenv("RUNLEVEL", argv[1]); |
837 | 832 | ||
838 | /* Hello world */ | 833 | /* Hello world */ |
839 | message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); | 834 | message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner); |
diff --git a/miscutils/crond.c b/miscutils/crond.c index 2f0bf6ea8..7d1908c63 100644 --- a/miscutils/crond.c +++ b/miscutils/crond.c | |||
@@ -187,7 +187,7 @@ int crond_main(int argc UNUSED_PARAM, char **argv) | |||
187 | 187 | ||
188 | xchdir(CDir); | 188 | xchdir(CDir); |
189 | //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */ | 189 | //signal(SIGHUP, SIG_IGN); /* ? original crond dies on HUP... */ |
190 | setenv("SHELL", DEFAULT_SHELL, 1); /* once, for all future children */ | 190 | xsetenv("SHELL", DEFAULT_SHELL); /* once, for all future children */ |
191 | crondlog(LVL9 "crond (busybox "BB_VER") started, log level %d", LogLevel); | 191 | crondlog(LVL9 "crond (busybox "BB_VER") started, log level %d", LogLevel); |
192 | SynchronizeDir(); | 192 | SynchronizeDir(); |
193 | 193 | ||
@@ -275,8 +275,8 @@ static void SetEnv(struct passwd *pas) | |||
275 | /* if we want to set user's shell instead: */ | 275 | /* if we want to set user's shell instead: */ |
276 | /*safe_setenv(env_var_user, "SHELL", pas->pw_shell, 5);*/ | 276 | /*safe_setenv(env_var_user, "SHELL", pas->pw_shell, 5);*/ |
277 | #else | 277 | #else |
278 | setenv("USER", pas->pw_name, 1); | 278 | xsetenv("USER", pas->pw_name); |
279 | setenv("HOME", pas->pw_dir, 1); | 279 | xsetenv("HOME", pas->pw_dir); |
280 | #endif | 280 | #endif |
281 | /* currently, we use constant one: */ | 281 | /* currently, we use constant one: */ |
282 | /*setenv("SHELL", DEFAULT_SHELL, 1); - done earlier */ | 282 | /*setenv("SHELL", DEFAULT_SHELL, 1); - done earlier */ |
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index f8662babb..ef6d94375 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -21,9 +21,9 @@ | |||
21 | 21 | ||
22 | static void change_user(const struct passwd *pas) | 22 | static void change_user(const struct passwd *pas) |
23 | { | 23 | { |
24 | setenv("USER", pas->pw_name, 1); | 24 | xsetenv("USER", pas->pw_name); |
25 | setenv("HOME", pas->pw_dir, 1); | 25 | xsetenv("HOME", pas->pw_dir); |
26 | setenv("SHELL", DEFAULT_SHELL, 1); | 26 | xsetenv("SHELL", DEFAULT_SHELL); |
27 | 27 | ||
28 | /* initgroups, setgid, setuid */ | 28 | /* initgroups, setgid, setuid */ |
29 | change_identity(pas); | 29 | change_identity(pas); |
diff --git a/networking/zcip.c b/networking/zcip.c index 221edd322..f406b6c16 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -144,7 +144,7 @@ static int run(char *argv[3], struct in_addr *ip) | |||
144 | 144 | ||
145 | if (ip) { | 145 | if (ip) { |
146 | addr = inet_ntoa(*ip); | 146 | addr = inet_ntoa(*ip); |
147 | setenv("ip", addr, 1); | 147 | xsetenv("ip", addr); |
148 | fmt -= 3; | 148 | fmt -= 3; |
149 | } | 149 | } |
150 | bb_info_msg(fmt, argv[1], intf, addr); | 150 | bb_info_msg(fmt, argv[1], intf, addr); |
@@ -238,7 +238,7 @@ int zcip_main(int argc, char **argv) | |||
238 | 238 | ||
239 | intf = argv[0]; | 239 | intf = argv[0]; |
240 | script_av[0] = argv[1]; | 240 | script_av[0] = argv[1]; |
241 | setenv("interface", intf, 1); | 241 | xsetenv("interface", intf); |
242 | 242 | ||
243 | // initialize the interface (modprobe, ifup, etc) | 243 | // initialize the interface (modprobe, ifup, etc) |
244 | script_av[1] = (char*)"init"; | 244 | script_av[1] = (char*)"init"; |