]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: handle or ignore SIGPIPE signal
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 1 Aug 2018 10:20:17 +0000 (12:20 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 3 Aug 2018 15:21:02 +0000 (17:21 +0200)
In chronyc handle SIGPIPE similarly to SIGTERM. In chronyd ignore the
signal to avoid crashing when a TCP socket will be needed (e.g. for
NTS-KE) and will be unexpectedly closed from the other side.

client.c
main.c
privops.c
util.c
util.h

index dab69ff8b78ae743f01f6e8ef77896b7f5eca6a9..cc00be84c1ce35ddff74e435bb40a5169ab03661 100644 (file)
--- a/client.c
+++ b/client.c
@@ -3258,7 +3258,7 @@ main(int argc, char **argv)
     hostnames = DEFAULT_COMMAND_SOCKET",127.0.0.1,::1";
   }
 
-  UTI_SetQuitSignalsHandler(signal_handler);
+  UTI_SetQuitSignalsHandler(signal_handler, 0);
 
   sockaddrs = get_sockaddrs(hostnames, port);
 
diff --git a/main.c b/main.c
index e538cc5b1de354070879693a191810785bb6ef2f..c40fb25e79796294b3ed7ca82a42d3437f2d5791 100644 (file)
--- a/main.c
+++ b/main.c
@@ -586,7 +586,7 @@ int main
   /* From now on, it is safe to do finalisation on exit */
   initialised = 1;
 
-  UTI_SetQuitSignalsHandler(signal_cleanup);
+  UTI_SetQuitSignalsHandler(signal_cleanup, 1);
 
   CAM_OpenUnixSocket();
 
index 359e1637aa800c6d4ccd2a91598322d8b7b4ad4b..8133351537ef91481db6ddf821d92fd731398458 100644 (file)
--- a/privops.c
+++ b/privops.c
@@ -700,7 +700,7 @@ PRV_StartHelper(void)
     }
 
     /* ignore signals, the process will exit on OP_QUIT request */
-    UTI_SetQuitSignalsHandler(SIG_IGN);
+    UTI_SetQuitSignalsHandler(SIG_IGN, 1);
 
     helper_main(sock_pair[1]);
 
diff --git a/util.c b/util.c
index 811914b7314143bb7c3e9afc606d70d623b3245d..bfbae33bd3527fb56d1168031124b10f4f30c6df 100644 (file)
--- a/util.c
+++ b/util.c
@@ -996,7 +996,7 @@ UTI_FdSetCloexec(int fd)
 /* ================================================== */
 
 void
-UTI_SetQuitSignalsHandler(void (*handler)(int))
+UTI_SetQuitSignalsHandler(void (*handler)(int), int ignore_sigpipe)
 {
   struct sigaction sa;
 
@@ -1021,6 +1021,12 @@ UTI_SetQuitSignalsHandler(void (*handler)(int))
   if (sigaction(SIGHUP, &sa, NULL) < 0)
     LOG_FATAL("sigaction(%d) failed", SIGHUP);
 #endif
+
+  if (ignore_sigpipe)
+    sa.sa_handler = SIG_IGN;
+
+  if (sigaction(SIGPIPE, &sa, NULL) < 0)
+    LOG_FATAL("sigaction(%d) failed", SIGPIPE);
 }
 
 /* ================================================== */
diff --git a/util.h b/util.h
index 96fdc76a909e1ea58953a30915cfa148b3a9079f..4c55651b1297c68edc4a6cdecf03721a2eb82210 100644 (file)
--- a/util.h
+++ b/util.h
@@ -161,7 +161,7 @@ extern Float UTI_FloatHostToNetwork(double x);
 /* Set FD_CLOEXEC on descriptor */
 extern int UTI_FdSetCloexec(int fd);
 
-extern void UTI_SetQuitSignalsHandler(void (*handler)(int));
+extern void UTI_SetQuitSignalsHandler(void (*handler)(int), int ignore_sigpipe);
 
 /* Get directory (as an allocated string) for a path */
 extern char *UTI_PathToDir(const char *path);