summaryrefslogtreecommitdiffstats
path: root/src/basic/terminal-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-08-20 17:30:15 +0200
committerLennart Poettering <lennart@poettering.net>2019-08-20 17:30:17 +0200
commit9281e703757e88c0097558ace965bd242ad1e07a (patch)
treeef3a2069e81946a024963294a062e6be0abf9bf9 /src/basic/terminal-util.c
parentlog: cast various log_open() calls to (void) (diff)
downloadsystemd-9281e703757e88c0097558ace965bd242ad1e07a.tar.xz
systemd-9281e703757e88c0097558ace965bd242ad1e07a.zip
terminal-util: add fallback logic to make_console_stdio()
If /dev/console can't be opened, let's use /dev/null instead. Inspired by: #13332
Diffstat (limited to 'src/basic/terminal-util.c')
-rw-r--r--src/basic/terminal-util.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index cf6af45fbb..c732e8021c 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -578,22 +578,29 @@ int vt_disallocate(const char *name) {
int make_console_stdio(void) {
int fd, r;
- /* Make /dev/console the controlling terminal and stdin/stdout/stderr */
+ /* Make /dev/console the controlling terminal and stdin/stdout/stderr, if we can. If we can't use
+ * /dev/null instead. This is particularly useful if /dev/console is turned off, e.g. if console=null
+ * is specified on the kernel command line. */
fd = acquire_terminal("/dev/console", ACQUIRE_TERMINAL_FORCE|ACQUIRE_TERMINAL_PERMISSIVE, USEC_INFINITY);
- if (fd < 0)
- return log_error_errno(fd, "Failed to acquire terminal: %m");
+ if (fd < 0) {
+ log_warning_errno(fd, "Failed to acquire terminal, using /dev/null stdin/stdout/stderr instead: %m");
- r = reset_terminal_fd(fd, true);
- if (r < 0)
- log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
+ r = make_null_stdio();
+ if (r < 0)
+ return log_error_errno(r, "Failed to make /dev/null stdin/stdout/stderr: %m");
- r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
- if (r < 0)
- return log_error_errno(r, "Failed to make terminal stdin/stdout/stderr: %m");
+ } else {
+ r = reset_terminal_fd(fd, true);
+ if (r < 0)
+ log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
- reset_terminal_feature_caches();
+ r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
+ if (r < 0)
+ return log_error_errno(r, "Failed to make terminal stdin/stdout/stderr: %m");
+ }
+ reset_terminal_feature_caches();
return 0;
}