From cd3bd60a2e4bb08526d953a323bbe1a0ace78b9e Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Jul 2012 19:19:59 +0200 Subject: switch-root: reopen /dev/console before we switch root --- src/core/shutdown.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'src/core/shutdown.c') diff --git a/src/core/shutdown.c b/src/core/shutdown.c index baef66dd9d..194a1ccf21 100644 --- a/src/core/shutdown.c +++ b/src/core/shutdown.c @@ -267,9 +267,10 @@ static int prepare_new_root(void) { } static int pivot_to_new_root(void) { - int fd; - - chdir("/run/initramfs"); + if (chdir("/run/initramfs") < 0) { + log_error("Failed to change directory to /run/initramfs: %m"); + return -errno; + } /* In case some evil process made "/" MS_SHARED @@ -288,18 +289,11 @@ static int pivot_to_new_root(void) { } chroot("."); - log_info("Successfully changed into root pivot."); - fd = open("/dev/console", O_RDWR); - if (fd < 0) - log_error("Failed to open /dev/console: %m"); - else { - make_stdio(fd); + setsid(); + make_console_stdio(); - /* Initialize the controlling terminal */ - setsid(); - ioctl(STDIN_FILENO, TIOCSCTTY, NULL); - } + log_info("Successfully changed into root pivot."); return 0; } -- cgit v1.2.3-54-g00ecf