From c63e2a383ec8fe55b472e57f157ee5bfae23bc9e Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 20 May 2024 10:20:43 +0200 Subject: [PATCH] hd-rum-transcode: handle SIGPIPE Similarly as for uv in commits 9e80a018 (2023-08-31) and afd0f217 (2023-09-13), handle SIGPIPE gracefully. This is useful when the output is redirected and the output is closed (which is the usual behavior, because the process with redirected output receives the signal when trying to write). --- src/hd-rum-translator/hd-rum-translator.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hd-rum-translator/hd-rum-translator.cpp b/src/hd-rum-translator/hd-rum-translator.cpp index e2e6b236a..47ea651c3 100644 --- a/src/hd-rum-translator/hd-rum-translator.cpp +++ b/src/hd-rum-translator/hd-rum-translator.cpp @@ -184,10 +184,14 @@ struct hd_rum_translator_state { static struct item *qinit(int qsize); static void qdestroy(struct item *queue); static void *writer(void *arg); -static void signal_handler(int signal); -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_DEBUG) { char msg[] = "Caught signal "; char buf[128]; @@ -195,10 +199,10 @@ static void signal_handler(int signal) for (size_t i = 0; i < sizeof msg - 1; ++i) { *ptr++ = msg[i]; } - if (signal / 10) { - *ptr++ = '0' + signal/10; - } - *ptr++ = '0' + signal%10; + if (signum / 10) { + *ptr++ = '0' + signum / 10; + } + *ptr++ = '0' + signum % 10; *ptr++ = '\n'; size_t bytes = ptr - buf; ptr = buf; @@ -1001,6 +1005,7 @@ int main(int argc, char **argv) sigaction(SIGTERM, &sa, NULL); sigaction(SIGHUP, &sa, NULL); sigaction(SIGABRT, &sa, NULL); + sigaction(SIGPIPE, &sa, NULL); signal(SIGQUIT, crash_signal_handler); signal(SIGALRM, hang_signal_handler); #else