diff options
author | Andrei Gherzan <andrei@gherzan.com> | 2017-03-24 16:39:08 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-03-24 16:39:08 +0100 |
commit | e3b65ab43d2e2d097a4cd2ee5aa1e1606a8a0663 (patch) | |
tree | 0cccd93b486de5994a8f5c998a78a85f479fadf2 /util-linux/switch_root.c | |
parent | 876c121ccb479d667a1ab00d0cb2d9cb1c298e7d (diff) | |
download | busybox-w32-e3b65ab43d2e2d097a4cd2ee5aa1e1606a8a0663.tar.gz busybox-w32-e3b65ab43d2e2d097a4cd2ee5aa1e1606a8a0663.tar.bz2 busybox-w32-e3b65ab43d2e2d097a4cd2ee5aa1e1606a8a0663.zip |
switch_root: don't bail out when console doesn't exist
Busybox is very often used in initramfs at the end of which usually
there is a switch_root to the actual rootfs. There are many cases where
the console kernel argument is either just a placeholder (for example
RaspberryPi uses serial0 and serial1) or configured as null to avoid any
console messages - usually you would see such of a setup in production
environments.
Currently busybox bails out if can't open the console argument. If this
happenes in initramfs and if the console=null for example, you get in a
blind kernel panic. Avoid this by only warning instead of dying.
function old new delta
switch_root_main 371 368 -3
Signed-off-by: Andrei Gherzan <andrei@gherzan.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/switch_root.c')
-rw-r--r-- | util-linux/switch_root.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index 6034485d7..aaee35a3e 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c | |||
@@ -141,10 +141,12 @@ int switch_root_main(int argc UNUSED_PARAM, char **argv) | |||
141 | 141 | ||
142 | // If a new console specified, redirect stdin/stdout/stderr to it | 142 | // If a new console specified, redirect stdin/stdout/stderr to it |
143 | if (console) { | 143 | if (console) { |
144 | close(0); | 144 | int fd = open_or_warn(console, O_RDWR); |
145 | xopen(console, O_RDWR); | 145 | if (fd >= 0) { |
146 | xdup2(0, 1); | 146 | xmove_fd(fd, 0); |
147 | xdup2(0, 2); | 147 | xdup2(0, 1); |
148 | xdup2(0, 2); | ||
149 | } | ||
148 | } | 150 | } |
149 | 151 | ||
150 | // Exec real init | 152 | // Exec real init |