diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-07-10 19:19:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-07-10 19:19:59 +0200 |
commit | cd3bd60a2e4bb08526d953a323bbe1a0ace78b9e (patch) | |
tree | 465cfcaa0896697ed0f0e7d4e144f9d4f1ffbbe3 /src/shared | |
parent | 94163dd54328780b4539e7296eb0ba75b7290367 (diff) |
switch-root: reopen /dev/console before we switch root
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 23 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 23 insertions, 1 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 62121b5923..63471899fd 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2940,7 +2940,8 @@ int make_stdio(int fd) { int make_null_stdio(void) { int null_fd; - if ((null_fd = open("/dev/null", O_RDWR|O_NOCTTY)) < 0) + null_fd = open("/dev/null", O_RDWR|O_NOCTTY); + if (null_fd < 0) return -errno; return make_stdio(null_fd); @@ -5844,3 +5845,23 @@ void warn_melody(void) { ioctl(fd, KIOCSOUND, 0); close_nointr_nofail(fd); } + +int make_console_stdio(void) { + int fd, r; + + /* Make /dev/console the controlling terminal and stdin/stdout/stderr */ + + fd = acquire_terminal("/dev/console", false, true, true, (usec_t) -1); + if (fd < 0) { + log_error("Failed to acquire terminal: %s", strerror(-fd)); + return fd; + } + + r = make_stdio(fd); + if (r < 0) { + log_error("Failed to duplicate terminal fd: %s", strerror(-r)); + return r; + } + + return 0; +} diff --git a/src/shared/util.h b/src/shared/util.h index 89e9a00afc..c8d048f9b2 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -278,6 +278,7 @@ char *format_timespan(char *buf, size_t l, usec_t t); int make_stdio(int fd); int make_null_stdio(void); +int make_console_stdio(void); unsigned long long random_ull(void); |