summaryrefslogtreecommitdiff
path: root/util-linux/switch_root.c
diff options
context:
space:
mode:
Diffstat (limited to 'util-linux/switch_root.c')
-rw-r--r--util-linux/switch_root.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
index 6034485..aaee35a 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)
// If a new console specified, redirect stdin/stdout/stderr to it
if (console) {
- close(0);
- xopen(console, O_RDWR);
- xdup2(0, 1);
- xdup2(0, 2);
+ int fd = open_or_warn(console, O_RDWR);
+ if (fd >= 0) {
+ xmove_fd(fd, 0);
+ xdup2(0, 1);
+ xdup2(0, 2);
+ }
}
// Exec real init