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:
parent
5bb2bf9361
commit
879d936277
5 changed files with 11 additions and 5 deletions
2
client.c
2
client.c
|
@ -3258,7 +3258,7 @@ main(int argc, char **argv)
|
||||||
hostnames = DEFAULT_COMMAND_SOCKET",127.0.0.1,::1";
|
hostnames = DEFAULT_COMMAND_SOCKET",127.0.0.1,::1";
|
||||||
}
|
}
|
||||||
|
|
||||||
UTI_SetQuitSignalsHandler(signal_handler);
|
UTI_SetQuitSignalsHandler(signal_handler, 0);
|
||||||
|
|
||||||
sockaddrs = get_sockaddrs(hostnames, port);
|
sockaddrs = get_sockaddrs(hostnames, port);
|
||||||
|
|
||||||
|
|
2
main.c
2
main.c
|
@ -586,7 +586,7 @@ int main
|
||||||
/* From now on, it is safe to do finalisation on exit */
|
/* From now on, it is safe to do finalisation on exit */
|
||||||
initialised = 1;
|
initialised = 1;
|
||||||
|
|
||||||
UTI_SetQuitSignalsHandler(signal_cleanup);
|
UTI_SetQuitSignalsHandler(signal_cleanup, 1);
|
||||||
|
|
||||||
CAM_OpenUnixSocket();
|
CAM_OpenUnixSocket();
|
||||||
|
|
||||||
|
|
|
@ -700,7 +700,7 @@ PRV_StartHelper(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ignore signals, the process will exit on OP_QUIT request */
|
/* ignore signals, the process will exit on OP_QUIT request */
|
||||||
UTI_SetQuitSignalsHandler(SIG_IGN);
|
UTI_SetQuitSignalsHandler(SIG_IGN, 1);
|
||||||
|
|
||||||
helper_main(sock_pair[1]);
|
helper_main(sock_pair[1]);
|
||||||
|
|
||||||
|
|
8
util.c
8
util.c
|
@ -996,7 +996,7 @@ UTI_FdSetCloexec(int fd)
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
UTI_SetQuitSignalsHandler(void (*handler)(int))
|
UTI_SetQuitSignalsHandler(void (*handler)(int), int ignore_sigpipe)
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
|
||||||
|
@ -1021,6 +1021,12 @@ UTI_SetQuitSignalsHandler(void (*handler)(int))
|
||||||
if (sigaction(SIGHUP, &sa, NULL) < 0)
|
if (sigaction(SIGHUP, &sa, NULL) < 0)
|
||||||
LOG_FATAL("sigaction(%d) failed", SIGHUP);
|
LOG_FATAL("sigaction(%d) failed", SIGHUP);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (ignore_sigpipe)
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
|
||||||
|
if (sigaction(SIGPIPE, &sa, NULL) < 0)
|
||||||
|
LOG_FATAL("sigaction(%d) failed", SIGPIPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
2
util.h
2
util.h
|
@ -161,7 +161,7 @@ extern Float UTI_FloatHostToNetwork(double x);
|
||||||
/* Set FD_CLOEXEC on descriptor */
|
/* Set FD_CLOEXEC on descriptor */
|
||||||
extern int UTI_FdSetCloexec(int fd);
|
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 */
|
/* Get directory (as an allocated string) for a path */
|
||||||
extern char *UTI_PathToDir(const char *path);
|
extern char *UTI_PathToDir(const char *path);
|
||||||
|
|
Loading…
Reference in a new issue