core/execute: introduce exec_input_is_inheritable() helper

This commit is contained in:
Mike Yuan
2025-12-17 23:23:22 +00:00
committed by Luca Boccassi
parent b34aee0440
commit e04382384d
2 changed files with 13 additions and 11 deletions
+10
View File
@@ -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,
+3 -11
View File
@@ -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)