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.
This commit is contained in:
Miroslav Lichvar
2018-08-01 12:20:17 +02:00
parent 5bb2bf9361
commit 879d936277
5 changed files with 11 additions and 5 deletions

8
util.c
View File

@@ -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);
}
/* ================================================== */