From: Miroslav Lichvar Date: Wed, 1 Aug 2018 10:20:17 +0000 (+0200) Subject: util: handle or ignore SIGPIPE signal X-Git-Tag: 3.4-pre1~71 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=879d936277382f189f8d29ee0a5ef3a6bed6f135;p=thirdparty%2Fchrony.git util: handle or ignore SIGPIPE signal 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. --- diff --git a/client.c b/client.c index dab69ff8..cc00be84 100644 --- 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 e538cc5b..c40fb25e 100644 --- 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(); diff --git a/privops.c b/privops.c index 359e1637..81333515 100644 --- 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 811914b7..bfbae33b 100644 --- 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 96fdc76a..4c55651b 100644 --- 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);