e20fafc72a
Resolves: RHEL-44417, RHEL-71409, RHEL-72798
173 lines
6.4 KiB
Diff
173 lines
6.4 KiB
Diff
From 2b379aa0cbce5c4ddee5ca118387503023b5474c Mon Sep 17 00:00:00 2001
|
|
From: Luca Boccassi <luca.boccassi@gmail.com>
|
|
Date: Thu, 19 Dec 2024 12:26:36 +0000
|
|
Subject: [PATCH] Revert "terminal-util: unify code that resets /dev/console in
|
|
common helper"
|
|
|
|
This reverts commit 2736295ddb78a457796f24805e7b98c3f5304848.
|
|
---
|
|
src/basic/terminal-util.c | 53 ++++++++++++++++-----------------------
|
|
src/basic/terminal-util.h | 3 ++-
|
|
src/core/main.c | 30 ++++++++++++++++------
|
|
3 files changed, 45 insertions(+), 41 deletions(-)
|
|
|
|
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
|
|
index 878c1ec06a..409f2abb45 100644
|
|
--- a/src/basic/terminal-util.c
|
|
+++ b/src/basic/terminal-util.c
|
|
@@ -577,7 +577,7 @@ static int vt_reset_keyboard(int fd) {
|
|
return RET_NERRNO(ioctl(fd, KDSKBMODE, kb));
|
|
}
|
|
|
|
-static int terminal_reset_ioctl(int fd, bool switch_to_text) {
|
|
+int terminal_reset_ioctl(int fd, bool switch_to_text) {
|
|
struct termios termios;
|
|
int r;
|
|
|
|
@@ -645,7 +645,7 @@ finish:
|
|
return r;
|
|
}
|
|
|
|
-static int terminal_reset_ansi_seq(int fd) {
|
|
+int terminal_reset_ansi_seq(int fd) {
|
|
int r, k;
|
|
|
|
assert(fd >= 0);
|
|
@@ -675,35 +675,6 @@ static int terminal_reset_ansi_seq(int fd) {
|
|
return k < 0 ? k : r;
|
|
}
|
|
|
|
-void reset_dev_console_fd(int fd, bool switch_to_text) {
|
|
- int r;
|
|
-
|
|
- assert(fd >= 0);
|
|
-
|
|
- _cleanup_close_ int lock_fd = lock_dev_console();
|
|
- if (lock_fd < 0)
|
|
- log_debug_errno(lock_fd, "Failed to lock /dev/console, ignoring: %m");
|
|
-
|
|
- r = terminal_reset_ioctl(fd, switch_to_text);
|
|
- if (r < 0)
|
|
- log_warning_errno(r, "Failed to reset /dev/console, ignoring: %m");
|
|
-
|
|
- unsigned rows, cols;
|
|
- r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
|
|
- if (r < 0)
|
|
- log_warning_errno(r, "Failed to get /dev/console size, ignoring: %m");
|
|
- else if (r > 0) {
|
|
- r = terminal_set_size_fd(fd, NULL, rows, cols);
|
|
- if (r < 0)
|
|
- log_warning_errno(r, "Failed to set configured terminal size on /dev/console, ignoring: %m");
|
|
- } else
|
|
- (void) terminal_fix_size(fd, fd);
|
|
-
|
|
- r = terminal_reset_ansi_seq(fd);
|
|
- if (r < 0)
|
|
- log_warning_errno(r, "Failed to reset /dev/console using ANSI sequences, ignoring: %m");
|
|
-}
|
|
-
|
|
int lock_dev_console(void) {
|
|
_cleanup_close_ int fd = -EBADF;
|
|
int r;
|
|
@@ -737,7 +708,25 @@ int make_console_stdio(void) {
|
|
return log_error_errno(r, "Failed to make /dev/null stdin/stdout/stderr: %m");
|
|
|
|
} else {
|
|
- reset_dev_console_fd(fd, /* switch_to_text= */ true);
|
|
+ unsigned rows, cols;
|
|
+
|
|
+ r = terminal_reset_ioctl(fd, /* switch_to_text= */ true);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
|
|
+
|
|
+ r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to get terminal size, ignoring: %m");
|
|
+ else if (r > 0) {
|
|
+ r = terminal_set_size_fd(fd, NULL, rows, cols);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to set configured terminal size, ignoring: %m");
|
|
+ } else
|
|
+ (void) terminal_fix_size(fd, fd);
|
|
+
|
|
+ r = terminal_reset_ansi_seq(fd);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to reset terminal using ANSI sequences, ignoring: %m");
|
|
|
|
r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
|
|
if (r < 0)
|
|
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
|
|
index c30faf168c..90662e2e66 100644
|
|
--- a/src/basic/terminal-util.h
|
|
+++ b/src/basic/terminal-util.h
|
|
@@ -39,6 +39,8 @@
|
|
|
|
bool isatty_safe(int fd);
|
|
|
|
+int terminal_reset_ioctl(int fd, bool switch_to_text);
|
|
+int terminal_reset_ansi_seq(int fd);
|
|
int terminal_reset_defensive(int fd, bool switch_to_text);
|
|
int terminal_reset_defensive_locked(int fd, bool switch_to_text);
|
|
|
|
@@ -101,7 +103,6 @@ bool tty_is_console(const char *tty) _pure_;
|
|
int vtnr_from_tty(const char *tty);
|
|
const char* default_term_for_tty(const char *tty);
|
|
|
|
-void reset_dev_console_fd(int fd, bool switch_to_text);
|
|
int lock_dev_console(void);
|
|
int make_console_stdio(void);
|
|
|
|
diff --git a/src/core/main.c b/src/core/main.c
|
|
index 172742c769..4bd2d8df75 100644
|
|
--- a/src/core/main.c
|
|
+++ b/src/core/main.c
|
|
@@ -245,18 +245,32 @@ unset:
|
|
}
|
|
|
|
static int console_setup(void) {
|
|
-
|
|
- if (getpid_cached() != 1)
|
|
- return 0;
|
|
-
|
|
_cleanup_close_ int tty_fd = -EBADF;
|
|
+ unsigned rows, cols;
|
|
+ int r;
|
|
|
|
- tty_fd = open_terminal("/dev/console", O_RDWR|O_NOCTTY|O_CLOEXEC);
|
|
+ tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
|
|
if (tty_fd < 0)
|
|
return log_error_errno(tty_fd, "Failed to open /dev/console: %m");
|
|
|
|
- /* We don't want to force text mode. Plymouth may be showing pictures already from initrd. */
|
|
- reset_dev_console_fd(tty_fd, /* switch_to_text= */ false);
|
|
+ /* We don't want to force text mode. plymouth may be showing
|
|
+ * pictures already from initrd. */
|
|
+ r = terminal_reset_ioctl(tty_fd, false);
|
|
+ if (r < 0)
|
|
+ return log_error_errno(r, "Failed to reset /dev/console: %m");
|
|
+
|
|
+ r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to get /dev/console size, ignoring: %m");
|
|
+ else {
|
|
+ r = terminal_set_size_fd(tty_fd, NULL, rows, cols);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to set /dev/console size, ignoring: %m");
|
|
+ }
|
|
+
|
|
+ r = terminal_reset_ansi_seq(tty_fd);
|
|
+ if (r < 0)
|
|
+ log_warning_errno(r, "Failed to reset /dev/console using ANSI sequences, ignoring: %m");
|
|
|
|
save_console_winsize_in_environment(tty_fd);
|
|
|
|
@@ -2977,7 +2991,7 @@ static void setup_console_terminal(bool skip_setup) {
|
|
(void) release_terminal();
|
|
|
|
/* Reset the console, but only if this is really init and we are freshly booted */
|
|
- if (!skip_setup)
|
|
+ if (getpid_cached() == 1 && !skip_setup)
|
|
(void) console_setup();
|
|
}
|
|
|