Skip to content

Commit 0de3c3b

Browse files
committed
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 f09a15d.
1 parent 6e6afa1 commit 0de3c3b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/supervise-daemon/supervise-daemon.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,20 @@ RC_NORETURN static void child_process(char *exec, char **argv)
610610

611611
cloexec_fds_from(3);
612612

613-
if (notify.type == NOTIFY_FD && dup2(notify.pipe[1], notify.fd) == -1)
614-
eerrorx("%s: failed to dup ready fd: %s", applet, strerror(errno));
613+
if (notify.type == NOTIFY_FD) {
614+
int error;
615+
616+
if (notify.fd == notify.pipe[1]) {
617+
int flags = error = fcntl(notify.fd, F_GETFD, 0);
618+
if (flags != -1)
619+
error = fcntl(notify.fd, F_SETFD, flags & ~FD_CLOEXEC);
620+
} else {
621+
error = dup2(notify.pipe[1], notify.fd);
622+
}
623+
624+
if (error)
625+
eerrorx("%s: failed to dup ready fd: %s", applet, strerror(errno));
626+
}
615627

616628
cmdline = make_cmdline(argv);
617629
syslog(LOG_INFO, "Child command line: %s", cmdline);

0 commit comments

Comments
 (0)