Skip to content

Commit ee0e2e5

Browse files
committed
Revert "terminal-util: unify code that resets /dev/console in common helper"
This reverts commit 2736295.
1 parent 8e039a2 commit ee0e2e5

File tree

3 files changed

+42
-35
lines changed

3 files changed

+42
-35
lines changed

src/basic/terminal-util.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -651,31 +651,6 @@ int vt_disallocate(const char *name) {
651651
return 0;
652652
}
653653

654-
void reset_dev_console_fd(int fd, bool switch_to_text) {
655-
int r;
656-
657-
assert(fd >= 0);
658-
659-
r = reset_terminal_fd(fd, switch_to_text);
660-
if (r < 0)
661-
log_warning_errno(r, "Failed to reset /dev/console, ignoring: %m");
662-
663-
unsigned rows, cols;
664-
r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
665-
if (r < 0)
666-
log_warning_errno(r, "Failed to get /dev/console size, ignoring: %m");
667-
else if (r > 0) {
668-
r = terminal_set_size_fd(fd, NULL, rows, cols);
669-
if (r < 0)
670-
log_warning_errno(r, "Failed to set configured terminal size on /dev/console, ignoring: %m");
671-
} else
672-
(void) terminal_fix_size(fd, fd);
673-
674-
r = terminal_reset_ansi_seq(fd);
675-
if (r < 0)
676-
log_warning_errno(r, "Failed to reset /dev/console using ANSI sequences, ignoring: %m");
677-
}
678-
679654
int make_console_stdio(void) {
680655
int fd, r;
681656

@@ -692,7 +667,25 @@ int make_console_stdio(void) {
692667
return log_error_errno(r, "Failed to make /dev/null stdin/stdout/stderr: %m");
693668

694669
} else {
695-
reset_dev_console_fd(fd, /* switch_to_text= */ true);
670+
unsigned rows, cols;
671+
672+
r = reset_terminal_fd(fd, /* switch_to_text= */ true);
673+
if (r < 0)
674+
log_warning_errno(r, "Failed to reset terminal, ignoring: %m");
675+
676+
r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
677+
if (r < 0)
678+
log_warning_errno(r, "Failed to get terminal size, ignoring: %m");
679+
else if (r > 0) {
680+
r = terminal_set_size_fd(fd, NULL, rows, cols);
681+
if (r < 0)
682+
log_warning_errno(r, "Failed to set configured terminal size, ignoring: %m");
683+
} else
684+
(void) terminal_fix_size(fd, fd);
685+
686+
r = terminal_reset_ansi_seq(fd);
687+
if (r < 0)
688+
log_warning_errno(r, "Failed to reset terminal using ANSI sequences, ignoring: %m");
696689

697690
r = rearrange_stdio(fd, fd, fd); /* This invalidates 'fd' both on success and on failure. */
698691
if (r < 0)

src/basic/terminal-util.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ bool tty_is_console(const char *tty) _pure_;
168168
int vtnr_from_tty(const char *tty);
169169
const char* default_term_for_tty(const char *tty);
170170

171-
void reset_dev_console_fd(int fd, bool switch_to_text);
172171
int make_console_stdio(void);
173172

174173
int getenv_columns(void);

src/core/main.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,33 @@ static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
208208
}
209209

210210
static int console_setup(void) {
211-
212-
if (getpid_cached() != 1)
213-
return 0;
214-
215211
_cleanup_close_ int tty_fd = -EBADF;
212+
unsigned rows, cols;
213+
int r;
216214

217-
tty_fd = open_terminal("/dev/console", O_RDWR|O_NOCTTY|O_CLOEXEC);
215+
tty_fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
218216
if (tty_fd < 0)
219217
return log_error_errno(tty_fd, "Failed to open /dev/console: %m");
220218

221-
/* We don't want to force text mode. Plymouth may be showing pictures already from initrd. */
222-
reset_dev_console_fd(tty_fd, /* switch_to_text= */ false);
219+
/* We don't want to force text mode. plymouth may be showing
220+
* pictures already from initrd. */
221+
r = reset_terminal_fd(tty_fd, false);
222+
if (r < 0)
223+
return log_error_errno(r, "Failed to reset /dev/console: %m");
224+
225+
r = proc_cmdline_tty_size("/dev/console", &rows, &cols);
226+
if (r < 0)
227+
log_warning_errno(r, "Failed to get /dev/console size, ignoring: %m");
228+
else {
229+
r = terminal_set_size_fd(tty_fd, NULL, rows, cols);
230+
if (r < 0)
231+
log_warning_errno(r, "Failed to set /dev/console size, ignoring: %m");
232+
}
233+
234+
r = terminal_reset_ansi_seq(tty_fd);
235+
if (r < 0)
236+
log_warning_errno(r, "Failed to reset /dev/console using ANSI sequences, ignoring: %m");
237+
223238
return 0;
224239
}
225240

@@ -2937,7 +2952,7 @@ static void setup_console_terminal(bool skip_setup) {
29372952
(void) release_terminal();
29382953

29392954
/* Reset the console, but only if this is really init and we are freshly booted */
2940-
if (!skip_setup)
2955+
if (getpid_cached() == 1 && !skip_setup)
29412956
(void) console_setup();
29422957
}
29432958

0 commit comments

Comments
 (0)