summaryrefslogtreecommitdiff
path: root/init/init.c
diff options
context:
space:
mode:
authorDenis Vlasenko2008-09-20 16:28:59 +0000
committerDenis Vlasenko2008-09-20 16:28:59 +0000
commitb8d1a4cd5f686ee95f6cf13634cba1f96e382f26 (patch)
tree86423f82c3593245aedae65e2e4c8f7e0c4d6482 /init/init.c
parentb61dc1c1cea7aaef3cd2aa016a9c7d4d1ffd71bf (diff)
downloadbusybox-b8d1a4cd5f686ee95f6cf13634cba1f96e382f26.zip
busybox-b8d1a4cd5f686ee95f6cf13634cba1f96e382f26.tar.gz
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
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/init/init.c b/init/init.c
index e02773c..e00a3b1 100644
--- a/init/init.c
+++ b/init/init.c
@@ -77,14 +77,6 @@ enum {
#endif
};
-static const char *const environment[] = {
- "HOME=/",
- bb_PATH_root_path,
- "SHELL=/bin/sh",
- "USER=root",
- NULL
-};
-
/* Function prototypes */
static void halt_reboot_pwoff(int sig) NORETURN;
@@ -118,15 +110,16 @@ static void message(int where, const char *fmt, ...)
{
static int log_fd = -1;
va_list arguments;
- int l;
+ unsigned l;
char msg[128];
msg[0] = '\r';
va_start(arguments, fmt);
- vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
+ l = vsnprintf(msg + 1, sizeof(msg) - 2, fmt, arguments);
+ if (l > sizeof(msg) - 2)
+ l = sizeof(msg) - 2;
+ msg[l] = '\0';
va_end(arguments);
- msg[sizeof(msg) - 2] = '\0';
- l = strlen(msg);
if (ENABLE_FEATURE_INIT_SYSLOG) {
/* Log the message to syslogd */
@@ -213,6 +206,8 @@ static void console_init(void)
/* Make sure fd 0,1,2 are not closed
* (so that they won't be used by future opens) */
bb_sanitize_stdio();
+ /* Make sure init can't be blocked by writing to stderr */
+ fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
}
s = getenv("TERM");
@@ -825,15 +820,15 @@ int init_main(int argc UNUSED_PARAM, char **argv)
set_sane_term();
xchdir("/");
setsid();
- {
- const char *const *e;
- /* Make sure environs is set to something sane */
- for (e = environment; *e; e++)
- putenv((char *) *e);
- }
+
+ /* Make sure environs is set to something sane */
+ putenv((char *) "HOME=/");
+ putenv((char *) bb_PATH_root_path);
+ putenv((char *) "SHELL=/bin/sh");
+ putenv((char *) "USER=root"); /* needed? why? */
if (argv[1])
- setenv("RUNLEVEL", argv[1], 1);
+ xsetenv("RUNLEVEL", argv[1]);
/* Hello world */
message(MAYBE_CONSOLE | L_LOG, "init started: %s", bb_banner);