diff --git a/client.c b/client.c index dab69ff..cc00be8 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 e538cc5..c40fb25 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 359e163..8133351 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 811914b..bfbae33 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 96fdc76..4c55651 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);