terminal-util: change 2nd parameter of terminal_reset_defensive() to flags
let's convert the 2nd argumeng form a boolean to a proper flags parameter. Doesn't change behaviour in anyway, but is more readable, and prepares ground for adding more flags soon.
This commit is contained in:
@@ -1930,7 +1930,7 @@ int terminal_set_cursor_position(int fd, unsigned row, unsigned column) {
|
||||
return loop_write(fd, cursor_position, SIZE_MAX);
|
||||
}
|
||||
|
||||
int terminal_reset_defensive(int fd, bool switch_to_text) {
|
||||
int terminal_reset_defensive(int fd, TerminalResetFlags flags) {
|
||||
int r = 0;
|
||||
|
||||
assert(fd >= 0);
|
||||
@@ -1946,7 +1946,7 @@ int terminal_reset_defensive(int fd, bool switch_to_text) {
|
||||
if (!isatty_safe(fd))
|
||||
return -ENOTTY;
|
||||
|
||||
RET_GATHER(r, terminal_reset_ioctl(fd, switch_to_text));
|
||||
RET_GATHER(r, terminal_reset_ioctl(fd, FLAGS_SET(flags, TERMINAL_RESET_SWITCH_TO_TEXT)));
|
||||
|
||||
if (terminal_is_pty_fd(fd) == 0)
|
||||
RET_GATHER(r, terminal_reset_ansi_seq(fd));
|
||||
@@ -1954,14 +1954,14 @@ int terminal_reset_defensive(int fd, bool switch_to_text) {
|
||||
return r;
|
||||
}
|
||||
|
||||
int terminal_reset_defensive_locked(int fd, bool switch_to_text) {
|
||||
int terminal_reset_defensive_locked(int fd, TerminalResetFlags flags) {
|
||||
assert(fd >= 0);
|
||||
|
||||
_cleanup_close_ int lock_fd = lock_dev_console();
|
||||
if (lock_fd < 0)
|
||||
log_debug_errno(lock_fd, "Failed to acquire lock for /dev/console, ignoring: %m");
|
||||
|
||||
return terminal_reset_defensive(fd, switch_to_text);
|
||||
return terminal_reset_defensive(fd, flags);
|
||||
}
|
||||
|
||||
void termios_disable_echo(struct termios *termios) {
|
||||
|
||||
@@ -41,8 +41,12 @@
|
||||
|
||||
bool isatty_safe(int fd);
|
||||
|
||||
int terminal_reset_defensive(int fd, bool switch_to_text);
|
||||
int terminal_reset_defensive_locked(int fd, bool switch_to_text);
|
||||
typedef enum TerminalResetFlags {
|
||||
TERMINAL_RESET_SWITCH_TO_TEXT = 1 << 0,
|
||||
} TerminalResetFlags;
|
||||
|
||||
int terminal_reset_defensive(int fd, TerminalResetFlags flags);
|
||||
int terminal_reset_defensive_locked(int fd, TerminalResetFlags flags);
|
||||
|
||||
int terminal_set_cursor_position(int fd, unsigned row, unsigned column);
|
||||
|
||||
|
||||
@@ -668,7 +668,7 @@ static int setup_confirm_stdio(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = terminal_reset_defensive(fd, /* switch_to_text= */ true);
|
||||
r = terminal_reset_defensive(fd, TERMINAL_RESET_SWITCH_TO_TEXT);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -4375,7 +4375,7 @@ static void prepare_terminal(
|
||||
if (lock_fd < 0)
|
||||
log_exec_debug_errno(context, p, lock_fd, "Failed to lock /dev/console, ignoring: %m");
|
||||
|
||||
(void) terminal_reset_defensive(STDOUT_FILENO, /* switch_to_text= */ false);
|
||||
(void) terminal_reset_defensive(STDOUT_FILENO, /* flags= */ 0);
|
||||
}
|
||||
|
||||
(void) exec_context_apply_tty_size(context, STDIN_FILENO, STDOUT_FILENO, /* tty_path= */ NULL);
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *p)
|
||||
log_warning_errno(lock_fd, "Failed to lock /dev/console, proceeding without lock: %m");
|
||||
|
||||
if (context->tty_reset)
|
||||
(void) terminal_reset_defensive(fd, /* switch_to_text= */ true);
|
||||
(void) terminal_reset_defensive(fd, TERMINAL_RESET_SWITCH_TO_TEXT);
|
||||
|
||||
r = exec_context_apply_tty_size(context, fd, fd, path);
|
||||
if (r < 0)
|
||||
|
||||
@@ -121,7 +121,7 @@ static void print_welcome(int rfd) {
|
||||
pn = os_release_pretty_name(pretty_name, os_name);
|
||||
ac = isempty(ansi_color) ? "0" : ansi_color;
|
||||
|
||||
(void) terminal_reset_defensive_locked(STDOUT_FILENO, /* switch_to_text= */ false);
|
||||
(void) terminal_reset_defensive_locked(STDOUT_FILENO, /* flags= */ 0);
|
||||
|
||||
if (colors_enabled())
|
||||
printf("\nWelcome to your new installation of \x1B[%sm%s\x1B[0m!\n", ac, pn);
|
||||
|
||||
+1
-1
@@ -2515,7 +2515,7 @@ static int create_interactively(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
(void) terminal_reset_defensive_locked(STDOUT_FILENO, /* switch_to_text= */ false);
|
||||
(void) terminal_reset_defensive_locked(STDOUT_FILENO, /* flags= */ 0);
|
||||
|
||||
for (;;) {
|
||||
username = mfree(username);
|
||||
|
||||
@@ -290,7 +290,7 @@ TEST(get_color_mode) {
|
||||
TEST(terminal_reset_defensive) {
|
||||
int r;
|
||||
|
||||
r = terminal_reset_defensive(STDOUT_FILENO, /* switch_to_text= */ false);
|
||||
r = terminal_reset_defensive(STDOUT_FILENO, /* flags= */ 0);
|
||||
if (r < 0)
|
||||
log_notice_errno(r, "Failed to reset terminal: %m");
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ static int agent_ask_password_tty(
|
||||
if (tty_fd < 0)
|
||||
return log_error_errno(tty_fd, "Failed to acquire %s: %m", con);
|
||||
|
||||
(void) terminal_reset_defensive_locked(tty_fd, /* switch_to_text= */ true);
|
||||
(void) terminal_reset_defensive_locked(tty_fd, TERMINAL_RESET_SWITCH_TO_TEXT);
|
||||
|
||||
log_info("Starting password query on %s.", con);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user