]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: wait for parent process to terminate
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 12 Jun 2023 14:11:10 +0000 (16:11 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 12 Jun 2023 14:40:53 +0000 (16:40 +0200)
When starting the daemon, wait in the grandparent process for the parent
process to terminate before exiting to avoid systemd logging a warning
"Supervising process $PID which is not our child". Waiting for the pipe
to be closed by the kernel when the parent process exits is not
sufficient.

Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
main.c

diff --git a/main.c b/main.c
index 31e3c8f0644e2e04c2bc20acea9a348b31952566..3233707844aabfa62234769a83c5b9eb496b6b2e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -331,6 +331,9 @@ go_daemon(void)
     char message[1024];
     int r;
 
+    /* Don't exit before the 'parent' */
+    waitpid(pid, NULL, 0);
+
     close(pipefd[1]);
     r = read(pipefd[0], message, sizeof (message));
     if (r) {
@@ -353,7 +356,9 @@ go_daemon(void)
     if (pid < 0) {
       LOG_FATAL("fork() failed : %s", strerror(errno));
     } else if (pid > 0) {
-      exit(0); /* In the 'parent' */
+      /* In the 'parent' */
+      close(pipefd[1]);
+      exit(0);
     } else {
       /* In the child we want to leave running as the daemon */