From 0de3c3baf801bbac07937a365435a6f734ef1939 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Wed, 19 Nov 2025 18:36:24 +0100 Subject: [PATCH] supervise-daemon: fix failure when notify fd matches pipe fd dup2 does not clear cloexec if dup2(n, n), causing the notify fd to be closed, see commit f09a15d4. --- src/supervise-daemon/supervise-daemon.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/supervise-daemon/supervise-daemon.c b/src/supervise-daemon/supervise-daemon.c index a1e870830..90325837f 100644 --- a/src/supervise-daemon/supervise-daemon.c +++ b/src/supervise-daemon/supervise-daemon.c @@ -610,8 +610,20 @@ RC_NORETURN static void child_process(char *exec, char **argv) cloexec_fds_from(3); - if (notify.type == NOTIFY_FD && dup2(notify.pipe[1], notify.fd) == -1) - eerrorx("%s: failed to dup ready fd: %s", applet, strerror(errno)); + if (notify.type == NOTIFY_FD) { + int error; + + if (notify.fd == notify.pipe[1]) { + int flags = error = fcntl(notify.fd, F_GETFD, 0); + if (flags != -1) + error = fcntl(notify.fd, F_SETFD, flags & ~FD_CLOEXEC); + } else { + error = dup2(notify.pipe[1], notify.fd); + } + + if (error) + eerrorx("%s: failed to dup ready fd: %s", applet, strerror(errno)); + } cmdline = make_cmdline(argv); syslog(LOG_INFO, "Child command line: %s", cmdline);