]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/exec-invoke: do not attempt to use fdstore/extra fds for stdio
authorMike Yuan <me@yhndnzj.com>
Wed, 29 Oct 2025 20:27:46 +0000 (21:27 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 30 Oct 2025 15:12:14 +0000 (16:12 +0100)
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.

src/core/exec-invoke.c

index 5b0245df33e605d5a3fd90e19e12a15fac78a8e5..14e2ea8f54af491b4a3550f09bb5904935a74fbe 100644 (file)
@@ -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])) {