From: Mike Yuan Date: Wed, 29 Oct 2025 20:27:46 +0000 (+0100) Subject: core/exec-invoke: do not attempt to use fdstore/extra fds for stdio X-Git-Tag: v259-rc1~217^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04072ad9ed8aa62cc5e8d72620a6861d84384278;p=thirdparty%2Fsystemd.git core/exec-invoke: do not attempt to use fdstore/extra fds for stdio According to systemd.exec(5): > The fd:name option connects standard input to a specific, named > file descriptor provided *by a socket unit*. ... Currently however we're looking at the whole fd array passed, fix it. --- diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 5b0245df33e..14e2ea8f54a 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -4745,9 +4745,8 @@ static int exec_context_named_iofds( const ExecParameters *p, int named_iofds[static 3]) { + const char *stdio_fdname[3]; size_t targets; - const char* stdio_fdname[3]; - size_t n_fds; assert(c); assert(p); @@ -4760,9 +4759,9 @@ static int exec_context_named_iofds( for (size_t i = 0; i < 3; i++) stdio_fdname[i] = exec_context_fdname(c, i); - n_fds = p->n_storage_fds + p->n_socket_fds + p->n_extra_fds; - - for (size_t i = 0; i < n_fds && targets > 0; i++) + /* Note that socket fds are always placed at the beginning of the fds array, no need for extra + * manipulation. */ + for (size_t i = 0; i < p->n_socket_fds && targets > 0; i++) if (named_iofds[STDIN_FILENO] < 0 && c->std_input == EXEC_INPUT_NAMED_FD && streq(p->fd_names[i], stdio_fdname[STDIN_FILENO])) {