]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: don't close -N descriptor after forking
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 23 Jun 2026 07:24:01 +0000 (09:24 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 30 Jun 2026 07:14:36 +0000 (09:14 +0200)
While this is not the expected use case, avoid closing the s6-style
notification file descriptor specified by the -N option after forking to
make it work even without the -d or -n option.

Fixes: 866bedef0b64 ("main: add -N option for s6-style service readiness notification")
main.c

diff --git a/main.c b/main.c
index c9ddca382c308b82196a69445c3942db9e570539..e317f5439b3be561ee3aeb11fb4ffb73ecaae817 100644 (file)
--- a/main.c
+++ b/main.c
@@ -70,7 +70,7 @@ static int exit_status = 0;
 
 static int reload = 0;
 
-static int notify_fd = 0;
+static int notify_fd = -1;
 
 static REF_Mode ref_mode = REF_ModeNormal;
 
@@ -113,11 +113,11 @@ static void
 notify_system_manager(int start)
 {
   /* s6-style ready notification using a pipe from the parent */
-  if (start && notify_fd) {
+  if (start && notify_fd >= 0) {
     if (write(notify_fd, "\n", 1) != 1)
       LOG_FATAL("Could not send notification requested by -N option");
     close(notify_fd);
-    notify_fd = 0;
+    notify_fd = -1;
   }
 
 #ifdef LINUX
@@ -416,9 +416,9 @@ go_daemon(void)
       }
 
       /* Don't keep stdin/out/err from before. But don't close
-         the parent pipe yet, or reusable file descriptors. */
+         the parent pipe, notification, and reusable file descriptors. */
       for (fd=0; fd<1024; fd++) {
-        if (fd != pipefd[1] && !SCK_IsReusable(fd))
+        if (fd != pipefd[1] && fd != notify_fd && !SCK_IsReusable(fd))
           close(fd);
       }