From: Mike Yuan Date: Sat, 22 Nov 2025 06:33:22 +0000 (+0100) Subject: core/execute: introduce exec_input_is_inheritable() helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e04382384de4d70d2d9178138ea7a68b304397ed;p=thirdparty%2Fsystemd.git core/execute: introduce exec_input_is_inheritable() helper --- diff --git a/src/core/execute.h b/src/core/execute.h index 42127347cf6..92a2c730fd9 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -480,6 +480,16 @@ static inline bool exec_context_has_tty(const ExecContext *context) { context->std_error == EXEC_OUTPUT_TTY; } +static inline bool exec_input_is_inheritable(ExecInput i) { + /* We assume these listed inputs refer to bidirectional streams, and hence duplicating them from + * stdin to stdout/stderr makes sense and hence allowing EXEC_OUTPUT_INHERIT makes sense, too. + * Outputs such as regular files or sealed data memfds otoh don't really make sense to be + * duplicated for both input and output at the same time (since they then would cause a feedback + * loop). */ + + return exec_input_is_terminal(i) || IN_SET(i, EXEC_INPUT_SOCKET, EXEC_INPUT_NAMED_FD); +} + int exec_spawn( Unit *unit, ExecCommand *command, diff --git a/src/core/service.c b/src/core/service.c index 9f7ccaaa412..3b594b5c5dc 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -808,19 +808,11 @@ static void service_fix_stdio(Service *s) { s->exec_context.stdin_data_size > 0) s->exec_context.std_input = EXEC_INPUT_DATA; - if (IN_SET(s->exec_context.std_input, - EXEC_INPUT_TTY, - EXEC_INPUT_TTY_FORCE, - EXEC_INPUT_TTY_FAIL, - EXEC_INPUT_SOCKET, - EXEC_INPUT_NAMED_FD)) + if (exec_input_is_inheritable(s->exec_context.std_input)) return; - /* We assume these listed inputs refer to bidirectional streams, and hence duplicating them from - * stdin to stdout/stderr makes sense and hence leaving EXEC_OUTPUT_INHERIT in place makes sense, - * too. Outputs such as regular files or sealed data memfds otoh don't really make sense to be - * duplicated for both input and output at the same time (since they then would cause a feedback - * loop), hence override EXEC_OUTPUT_INHERIT with the default stderr/stdout setting. */ + /* Override EXEC_OUTPUT_INHERIT with the default stderr/stdout setting if not applicable for + * given stdin mode. */ if (s->exec_context.std_error == EXEC_OUTPUT_INHERIT && s->exec_context.std_output == EXEC_OUTPUT_INHERIT)