]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: do not touch tty when StandardOutput=/StandardError=journal+console/kmsg+console
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Aug 2025 07:54:59 +0000 (16:54 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 13 Aug 2025 14:44:42 +0000 (23:44 +0900)
src/core/exec-invoke.c
src/core/execute.c
src/core/execute.h

index 0a5f455369a6b6e57adea660218fe90f52dd0db0..1e2945eb910ef1dcf2111a829f6889a66e977629 100644 (file)
@@ -4860,7 +4860,7 @@ static void prepare_terminal(
         assert(p);
 
         /* We only try to reset things if we there's the chance our stdout points to a TTY */
-        if (!(exec_output_is_terminal(context->std_output) ||
+        if (!(context->std_output == EXEC_OUTPUT_TTY ||
               (context->std_output == EXEC_OUTPUT_INHERIT && exec_input_is_terminal(context->std_input)) ||
               context->std_output == EXEC_OUTPUT_NAMED_FD ||
               p->stdout_fd >= 0))
@@ -4901,10 +4901,7 @@ static int setup_term_environment(const ExecContext *context, char ***env) {
                 return 0;
 
         /* Do we need $TERM at all? */
-        if (!exec_input_is_terminal(context->std_input) &&
-            !exec_output_is_terminal(context->std_output) &&
-            !exec_output_is_terminal(context->std_error) &&
-            !context->tty_path)
+        if (!exec_context_has_tty(context))
                 return 0;
 
         const char *tty_path = exec_context_tty_path(context);
index b998bdb367d5cb8913d7ad7e16783dc2cac4b991..fa63a6bee05d60edd338013155f1e66ade0aa0a8 100644 (file)
@@ -137,8 +137,7 @@ void exec_context_tty_reset(const ExecContext *context, const ExecParameters *pa
 
         if (parameters && parameters->stdout_fd >= 0 && isatty_safe(parameters->stdout_fd))
                 fd = parameters->stdout_fd;
-        else if (path && (context->tty_path || exec_input_is_terminal(context->std_input) ||
-                        exec_output_is_terminal(context->std_output) || exec_output_is_terminal(context->std_error))) {
+        else if (path && exec_context_has_tty(context)) {
                 fd = _fd = open_terminal(path, O_RDWR|O_NOCTTY|O_CLOEXEC|O_NONBLOCK);
                 if (fd < 0)
                         return (void) log_debug_errno(fd, "Failed to open terminal '%s', ignoring: %m", path);
@@ -987,8 +986,8 @@ static bool exec_context_may_touch_tty(const ExecContext *ec) {
                 ec->tty_vhangup ||
                 ec->tty_vt_disallocate ||
                 exec_input_is_terminal(ec->std_input) ||
-                exec_output_is_terminal(ec->std_output) ||
-                exec_output_is_terminal(ec->std_error);
+                ec->std_output == EXEC_OUTPUT_TTY ||
+                ec->std_error == EXEC_OUTPUT_TTY;
 }
 
 bool exec_context_may_touch_console(const ExecContext *ec) {
index ce6483260a3d1b67e05f8e3a5e0ade97b082747e..2e30374830ae4ea09df92a74f4d4dcbf98ec212d 100644 (file)
@@ -478,6 +478,16 @@ static inline bool exec_output_is_kmsg(ExecOutput o) {
                       EXEC_OUTPUT_KMSG_AND_CONSOLE);
 }
 
+static inline bool exec_context_has_tty(const ExecContext *context) {
+        assert(context);
+
+        return
+                context->tty_path ||
+                exec_input_is_terminal(context->std_input) ||
+                context->std_output == EXEC_OUTPUT_TTY ||
+                context->std_error == EXEC_OUTPUT_TTY;
+}
+
 int exec_spawn(
                 Unit *unit,
                 ExecCommand *command,