From fb274df0797f58cda0b3b6809769707fe21e40e7 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 17 Mar 2008 13:26:51 +0000 Subject: init: do not use bb_sanitize_stdio(), "/dev/null" may be missing (yet) --- init/init.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'init/init.c') diff --git a/init/init.c b/init/init.c index 6d4969c4b..eefb9df55 100644 --- a/init/init.c +++ b/init/init.c @@ -219,8 +219,22 @@ static void console_init(void) } messageD(L_LOG, "console='%s'", s); } else { - /* Make sure fd 0,1,2 are not closed */ - bb_sanitize_stdio(); + /* Make sure fd 0,1,2 are not closed + * (so that they won't be used by future opens) */ + + /* bb_sanitize_stdio(); - WRONG. + * Fail if "/dev/null" doesnt exist, and for init + * this is a real possibility! Open code it instead. */ + + int fd = open(bb_dev_null, O_RDWR); + if (fd < 0) { + /* Give me _ANY_ open descriptor! */ + fd = xopen("/", O_RDONLY); /* we don't believe this can fail */ + } + while ((unsigned)fd < 2) + fd = dup(fd); + if (fd > 2) + close (fd); } s = getenv("TERM"); -- cgit v1.2.3