From afd0f217def5e35609be5e5dec6fcfacf3eecfb8 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 19 Sep 2023 13:33:49 +0200 Subject: [PATCH] signal_handler: ignore next SIGPIPE signals We will end anyways and do not produce additional SIGPIPE on eventual output. --- src/main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 962206a07..a8b6fdb34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -174,17 +174,22 @@ struct state_uv { static constexpr uint32_t state_magic = to_fourcc('U', 'G', 'S', 'T'); }; -static void signal_handler(int signal) +static void signal_handler(int signum) { +#ifdef SIGPIPE + if (signum == SIGPIPE) { + signal(SIGPIPE, SIG_IGN); + } +#endif // defined SIGPIPE if (log_level >= LOG_LEVEL_VERBOSE) { char buf[128]; char *ptr = buf; char *ptr_end = buf + sizeof buf; strappend(&ptr, ptr_end, "Caught signal "); - if (signal / 10) { - *ptr++ = '0' + signal/10; + if (signum / 10 != 0) { + *ptr++ = (char) ('0' + signum / 10); } - *ptr++ = '0' + signal%10; + *ptr++ = (char) ('0' + signum % 10); *ptr++ = '\n'; write_all(ptr - buf, buf); }