switch-root: reopen /dev/console before we switch root
This commit is contained in:
+6
-8
@@ -164,16 +164,11 @@ _noreturn_ static void crash(int sig) {
|
||||
sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART;
|
||||
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
|
||||
|
||||
if ((pid = fork()) < 0)
|
||||
pid = fork();
|
||||
if (pid < 0)
|
||||
log_error("Failed to fork off crash shell: %s", strerror(errno));
|
||||
else if (pid == 0) {
|
||||
int fd, r;
|
||||
|
||||
if ((fd = acquire_terminal("/dev/console", false, true, true, (usec_t) -1)) < 0)
|
||||
log_error("Failed to acquire terminal: %s", strerror(-fd));
|
||||
else if ((r = make_stdio(fd)) < 0)
|
||||
log_error("Failed to duplicate terminal fd: %s", strerror(-r));
|
||||
|
||||
make_console_stdio();
|
||||
execl("/bin/sh", "/bin/sh", NULL);
|
||||
|
||||
log_error("execl() failed: %s", strerror(errno));
|
||||
@@ -1677,6 +1672,9 @@ finish:
|
||||
* rebooted while we do that */
|
||||
watchdog_close(true);
|
||||
|
||||
/* Reopen the console */
|
||||
make_console_stdio();
|
||||
|
||||
if (switch_root_dir) {
|
||||
r = switch_root(switch_root_dir);
|
||||
if (r < 0)
|
||||
|
||||
+8
-14
@@ -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,19 +289,12 @@ static int pivot_to_new_root(void) {
|
||||
}
|
||||
|
||||
chroot(".");
|
||||
|
||||
setsid();
|
||||
make_console_stdio();
|
||||
|
||||
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);
|
||||
|
||||
/* Initialize the controlling terminal */
|
||||
setsid();
|
||||
ioctl(STDIN_FILENO, TIOCSCTTY, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user