From d48e81f0cda73aca49cd852212a62e879cf35b86 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 6 Jul 2008 07:00:11 +0000 Subject: mdev: do not follow symlinks in /sys (as was intended prior to rev 18811). If this breaks things, please document why! mdev,init: use shared code for fd sanitization function old new delta bb_daemonize_or_rexec 155 172 +17 mdev_main 500 505 +5 init_main 907 856 -51 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 22/-51) Total: -29 bytes --- libbb/vfork_daemon_rexec.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'libbb/vfork_daemon_rexec.c') diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 37d4c274e..da0dc03e5 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c @@ -265,7 +265,14 @@ void FAST_FUNC bb_daemonize_or_rexec(int flags, char **argv) close(2); } - fd = xopen(bb_dev_null, O_RDWR); + fd = open(bb_dev_null, O_RDWR); + if (fd < 0) { + /* NB: we can be called as bb_sanitize_stdio() from init + * or mdev, and there /dev/null may legitimately not (yet) exist! + * Do not use xopen above, but obtain _ANY_ open descriptor, + * even bogus one as below. */ + fd = xopen("/", O_RDONLY); /* don't believe this can fail */ + } while ((unsigned)fd < 2) fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ -- cgit v1.2.3