]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
main: check for killed foreground process
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2024 14:11:19 +0000 (16:11 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2024 14:50:22 +0000 (16:50 +0200)
On start, if the foreground process waiting for the daemon process to
close the pipe (after finishing the RTC initialization, initstepslew,
etc) is killed, terminate the daemon too assuming that whatever killed
the foreground process it wanted all chronyd processes to stop.

In the daemon, before closing the pipe file descriptor, send an empty
message to check if the pipe isn't already closed on the other end.

main.c

diff --git a/main.c b/main.c
index cb2406400a267067f81ebe5f44bf55a703379606..88ada20224e3792fd4e1436e6bd244513723b943 100644 (file)
--- a/main.c
+++ b/main.c
@@ -215,7 +215,10 @@ post_init_ntp_hook(void *anything)
     REF_SetMode(ref_mode);
   }
 
-  /* Close the pipe to the foreground process so it can exit */
+  /* Send an empty message to the foreground process so it can exit.
+     If that fails, indicating the process was killed, exit too. */
+  if (!LOG_NotifyParent(""))
+    SCH_QuitProgram();
   LOG_CloseParentFd();
 
   CNF_AddSources();
@@ -338,8 +341,8 @@ go_daemon(void)
 
     close(pipefd[1]);
     r = read(pipefd[0], message, sizeof (message));
-    if (r) {
-      if (r > 0) {
+    if (r != 1 || message[0] != '\0') {
+      if (r > 1) {
         /* Print the error message from the child */
         message[sizeof (message) - 1] = '\0';
         fprintf(stderr, "%s\n", message);