]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: close pipe in grandparent process
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 13:35:58 +0000 (14:35 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 28 Nov 2024 13:35:58 +0000 (14:35 +0100)
Close the other end of the pipe in the grandparent process before exit
to avoid valgrind error.

Also, in the daemon process avoid closing the pipe for second time in
the 0-1024 close() loop to avoid another error.

main.c

diff --git a/main.c b/main.c
index 88ada20224e3792fd4e1436e6bd244513723b943..864dec2d3924d3a304d0868364c185261a3e9f48 100644 (file)
--- a/main.c
+++ b/main.c
@@ -339,8 +339,11 @@ go_daemon(void)
     /* Don't exit before the 'parent' */
     waitpid(pid, NULL, 0);
 
-    close(pipefd[1]);
     r = read(pipefd[0], message, sizeof (message));
+
+    close(pipefd[0]);
+    close(pipefd[1]);
+
     if (r != 1 || message[0] != '\0') {
       if (r > 1) {
         /* Print the error message from the child */
@@ -351,8 +354,6 @@ go_daemon(void)
     } else
       exit(0);
   } else {
-    close(pipefd[0]);
-
     setsid();
 
     /* Do 2nd fork, as-per recommended practice for launching daemons. */
@@ -362,6 +363,7 @@ go_daemon(void)
       LOG_FATAL("fork() failed : %s", strerror(errno));
     } else if (pid > 0) {
       /* In the 'parent' */
+      close(pipefd[0]);
       close(pipefd[1]);
       exit(0);
     } else {