mirror of
https://github.com/systemd/systemd.git
synced 2025-03-28 02:50:16 +03:00
Revert "terminal-util: unify code that resets /dev/console in common helper"
This reverts commit 2736295ddb78a457796f24805e7b98c3f5304848.
This commit is contained in:
parent
9c8559bccf
commit
2b379aa0cb
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user