From 759a9d0cc56c074567e0048fc0a1058bc179a101 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 25 May 2009 23:56:38 +0200 Subject: [PATCH] core-util: introduce pa_disable_sigpipe() --- src/daemon/main.c | 4 +--- src/pulsecore/core-util.c | 21 +++++++++++++++++++++ src/pulsecore/core-util.h | 2 ++ src/utils/pabrowse.c | 4 +++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/daemon/main.c b/src/daemon/main.c index a232451..3e50baa 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -946,9 +946,7 @@ int main(int argc, char *argv[]) { valid_pid_file = TRUE; } -#ifdef SIGPIPE - signal(SIGPIPE, SIG_IGN); -#endif + pa_disable_sigpipe(); if (pa_rtclock_hrtimer()) pa_log_info(_("Fresh high-resolution timers available! Bon appetit!")); diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c index d4956fb..b747cd8 100644 --- a/src/pulsecore/core-util.c +++ b/src/pulsecore/core-util.c @@ -2711,3 +2711,24 @@ char *pa_realpath(const char *path) { return t; } + +void pa_disable_sigpipe(void) { + +#ifdef SIGPIPE + struct sigaction sa; + + pa_zero(sa); + + if (sigaction(SIGPIPE, NULL, &sa) < 0) { + pa_log("sigaction(): %s", pa_cstrerror(errno)); + return; + } + + sa.sa_handler = SIG_IGN; + + if (sigaction(SIGPIPE, &sa, NULL) < 0) { + pa_log("sigaction(): %s", pa_cstrerror(errno)); + return; + } +#endif +} diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 91a4c55..d073b75 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -227,4 +227,6 @@ char *pa_unescape(char *p); char *pa_realpath(const char *path); +void pa_disable_sigpipe(void); + #endif diff --git a/src/utils/pabrowse.c b/src/utils/pabrowse.c index 288d44a..a6487b8 100644 --- a/src/utils/pabrowse.c +++ b/src/utils/pabrowse.c @@ -30,6 +30,8 @@ #include #include +#include + static void exit_signal_callback(pa_mainloop_api*m, pa_signal_event *e, int sig, void *userdata) { fprintf(stderr, "Got signal, exiting\n"); m->quit(m, 0); @@ -127,7 +129,7 @@ int main(int argc, char *argv[]) { assert(r == 0); pa_signal_new(SIGINT, exit_signal_callback, NULL); pa_signal_new(SIGTERM, exit_signal_callback, NULL); - signal(SIGPIPE, SIG_IGN); + pa_disable_sigpipe(); if (!(browser = pa_browser_new_full(pa_mainloop_get_api(mainloop), PA_BROWSE_FOR_SERVERS|PA_BROWSE_FOR_SINKS|PA_BROWSE_FOR_SOURCES, &s))) { fprintf(stderr, "pa_browse_new_full(): %s\n", s); -- 2.7.4