]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: change 2nd parameter of terminal_reset_defensive() to flags
authorLennart Poettering <lennart@poettering.net>
Fri, 31 Jan 2025 14:30:07 +0000 (15:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Feb 2025 14:13:15 +0000 (15:13 +0100)
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.

src/basic/terminal-util.c
src/basic/terminal-util.h
src/core/exec-invoke.c
src/core/execute.c
src/firstboot/firstboot.c
src/home/homectl.c
src/test/test-terminal-util.c
src/tty-ask-password-agent/tty-ask-password-agent.c

index fce3bb95a3cffce52ac661e74c422a4153218d70..1ff0dbcedc34c0725d295f6eba3c64621a98ab38 100644 (file)
@@ -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) {
index 698838e63f9fa1ff0f218d9bb72d05729b83271b..e2c4a83230467487c580e059b912db59963b0f37 100644 (file)
 
 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);
 
index 10f425139bff371744a73ed97369bbd7119b5c9a..8d48d1f75a14acb3d06cb7337a72c3d5bfc39596 100644 (file)
@@ -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);
index 6811bf301ca268b7187e5fac63625ea64d244e43..62b9e6e221beb9bdb925268cb461d4a1cfdb661b 100644 (file)
@@ -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)
index 99e75b34224de12dbdd9f19dd9d5c168cbe14ff7..9ef8d89560e3db6f31dcfd695949951b57d2f28e 100644 (file)
@@ -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);
index c398b324fdd8e9ba00226e71b309e94ac6f73d82..a7754c22998abb7e31cc12a8a4f6209e5d926944 100644 (file)
@@ -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);
index 87304346e9e1e41e0de36f435ee24db523461270..a5616c81212f5ff70c7949d39bd9d06123b55e83 100644 (file)
@@ -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");
 }
index 6950a8697ee55ba9b1370b67e55fe282352c7a3e..b3471e272f54afcb57dc84409b140b570c2c59ce 100644 (file)
@@ -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);
         }