aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-06 07:00:11 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-06 07:00:11 +0000
commitd48e81f0cda73aca49cd852212a62e879cf35b86 (patch)
treebc7f639f139f1fe5d65dd20b5819d41a5acf2cea
parentff182a3d68462cb7ec38affa1afb04a06031862f (diff)
downloadbusybox-w32-d48e81f0cda73aca49cd852212a62e879cf35b86.tar.gz
busybox-w32-d48e81f0cda73aca49cd852212a62e879cf35b86.tar.bz2
busybox-w32-d48e81f0cda73aca49cd852212a62e879cf35b86.zip
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
-rw-r--r--init/init.c15
-rw-r--r--libbb/vfork_daemon_rexec.c9
-rw-r--r--util-linux/mdev.c17
3 files changed, 21 insertions, 20 deletions
diff --git a/init/init.c b/init/init.c
index 232896709..4b2bd9c77 100644
--- a/init/init.c
+++ b/init/init.c
@@ -221,20 +221,7 @@ static void console_init(void)
221 } else { 221 } else {
222 /* Make sure fd 0,1,2 are not closed 222 /* Make sure fd 0,1,2 are not closed
223 * (so that they won't be used by future opens) */ 223 * (so that they won't be used by future opens) */
224 224 bb_sanitize_stdio();
225 /* bb_sanitize_stdio(); - WRONG.
226 * It fails if "/dev/null" doesnt exist, and for init
227 * this is a real possibility! Open code it instead. */
228
229 int fd = open(bb_dev_null, O_RDWR);
230 if (fd < 0) {
231 /* Give me _ANY_ open descriptor! */
232 fd = xopen("/", O_RDONLY); /* we don't believe this can fail */
233 }
234 while ((unsigned)fd < 2)
235 fd = dup(fd);
236 if (fd > 2)
237 close(fd);
238 } 225 }
239 226
240 s = getenv("TERM"); 227 s = getenv("TERM");
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)
265 close(2); 265 close(2);
266 } 266 }
267 267
268 fd = xopen(bb_dev_null, O_RDWR); 268 fd = open(bb_dev_null, O_RDWR);
269 if (fd < 0) {
270 /* NB: we can be called as bb_sanitize_stdio() from init
271 * or mdev, and there /dev/null may legitimately not (yet) exist!
272 * Do not use xopen above, but obtain _ANY_ open descriptor,
273 * even bogus one as below. */
274 fd = xopen("/", O_RDONLY); /* don't believe this can fail */
275 }
269 276
270 while ((unsigned)fd < 2) 277 while ((unsigned)fd < 2)
271 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */ 278 fd = dup(fd); /* have 0,1,2 open at least to /dev/null */
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index c7109373d..9c4938a70 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -19,7 +19,8 @@ struct globals {
19#define root_major (G.root_major) 19#define root_major (G.root_major)
20#define root_minor (G.root_minor) 20#define root_minor (G.root_minor)
21 21
22#define MAX_SYSFS_DEPTH 3 /* prevent infinite loops in /sys symlinks */ 22/* Prevent infinite loops in /sys symlinks */
23#define MAX_SYSFS_DEPTH 3
23 24
24/* We use additional 64+ bytes in make_device() */ 25/* We use additional 64+ bytes in make_device() */
25#define SCRATCH_SIZE 80 26#define SCRATCH_SIZE 80
@@ -392,11 +393,17 @@ int mdev_main(int argc, char **argv)
392 char *env_path; 393 char *env_path;
393 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE); 394 RESERVE_CONFIG_BUFFER(temp, PATH_MAX + SCRATCH_SIZE);
394 395
395#ifdef YOU_WANT_TO_DEBUG_HOTPLUG_EVENTS 396 /* We can be called as hotplug helper */
396 /* Kernel cannot provide suitable stdio fds for us, do it ourself */ 397 /* Kernel cannot provide suitable stdio fds for us, do it ourself */
398#if 1
399 bb_sanitize_stdio();
400#else
401 /* Debug code */
397 /* Replace LOGFILE by other file or device name if you need */ 402 /* Replace LOGFILE by other file or device name if you need */
398#define LOGFILE "/dev/console" 403#define LOGFILE "/dev/console"
399 xmove_fd(xopen("/dev/null", O_RDONLY), STDIN_FILENO); 404 /* Just making sure fd 0 is not closed,
405 * we don't really intend to read from it */
406 xmove_fd(xopen("/", O_RDONLY), STDIN_FILENO);
400 xmove_fd(xopen(LOGFILE, O_WRONLY|O_APPEND), STDOUT_FILENO); 407 xmove_fd(xopen(LOGFILE, O_WRONLY|O_APPEND), STDOUT_FILENO);
401 xmove_fd(xopen(LOGFILE, O_WRONLY|O_APPEND), STDERR_FILENO); 408 xmove_fd(xopen(LOGFILE, O_WRONLY|O_APPEND), STDERR_FILENO);
402#endif 409#endif
@@ -414,11 +421,11 @@ int mdev_main(int argc, char **argv)
414 root_minor = minor(st.st_dev); 421 root_minor = minor(st.st_dev);
415 422
416 recursive_action("/sys/block", 423 recursive_action("/sys/block",
417 ACTION_RECURSE | ACTION_FOLLOWLINKS, 424 ACTION_RECURSE /* no ACTION_FOLLOWLINKS! */,
418 fileAction, dirAction, temp, 0); 425 fileAction, dirAction, temp, 0);
419 426
420 recursive_action("/sys/class", 427 recursive_action("/sys/class",
421 ACTION_RECURSE | ACTION_FOLLOWLINKS, 428 ACTION_RECURSE /* no ACTION_FOLLOWLINKS! */,
422 fileAction, dirAction, temp, 0); 429 fileAction, dirAction, temp, 0);
423 430
424 } else { 431 } else {