Skip to content

Commit

Permalink
Ignore SIGPIPE and let send fail with an error instead of killing the…
Browse files Browse the repository at this point in the history
… process
  • Loading branch information
guillep committed Aug 30, 2021
1 parent 2e3d3fa commit 8ba1e7e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/debugUnix.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ EXPORT(void) registerCurrentThreadToHandleExceptions(){
}

EXPORT(void) installErrorHandlers(){
struct sigaction sigusr1_handler_action, sigsegv_handler_action, term_handler_action;
struct sigaction sigusr1_handler_action, sigsegv_handler_action, term_handler_action, sigpipe_handler_action;

sigsegv_handler_action.sa_sigaction = (void (*)(int, siginfo_t *, void *))sigsegv;
sigsegv_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
Expand All @@ -125,6 +125,12 @@ EXPORT(void) installErrorHandlers(){
sigaction(SIGTERM, &term_handler_action, 0);
sigaction(SIGKILL, &term_handler_action, 0);
sigaction(SIGHUP, &term_handler_action, 0);

//Ignore all broken pipe signals. They will be reported as normal errors by send() and write()
//Otherwise SIGPIPE kill the process without allowing any recovery or treatment
sigpipe_handler_action.sa_sigaction = (void (*)(int, siginfo_t *, void *))SIG_IGN;
sigpipe_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGPIPE, &sigpipe_handler_action, 0);

sigusr1_handler_action.sa_sigaction = (void (*)(int, siginfo_t *, void *))sigusr1;
sigusr1_handler_action.sa_flags = SA_NODEFER | SA_SIGINFO;
Expand Down

0 comments on commit 8ba1e7e

Please sign in to comment.