From da88419ae8165248621cad26df72a0d91663d50b Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 12 Jan 2017 21:26:59 -0800 Subject: Block SIGPIPE. Ewww... --- src/platform/posix/posix_impl.h | 4 +++- src/platform/posix/posix_thread.c | 23 ++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index c155e15c..1ab728c5 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -64,7 +64,9 @@ struct nni_plat_mtx { }; struct nni_plat_thr { - pthread_t tid; + pthread_t tid; + void (*func)(void *); + void * arg; }; struct nni_plat_cv { diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index 991a08db..0ca9c18d 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -20,6 +20,7 @@ #include #include #include +#include static pthread_mutex_t nni_plat_lock = PTHREAD_MUTEX_INITIALIZER; static int nni_plat_inited = 0; @@ -178,13 +179,33 @@ nni_plat_cv_fini(nni_plat_cv *cv) } +static void * +nni_plat_thr_main(void *arg) +{ + nni_plat_thr *thr = arg; + sigset_t set; + + // Suppress (block) SIGPIPE for this thread. + sigemptyset(&set); + sigaddset(&set, SIGPIPE); + (void) pthread_sigmask(SIG_BLOCK, &set, NULL); + + thr->func(thr->arg); + return (NULL); +} + + int nni_plat_thr_init(nni_plat_thr *thr, void (*fn)(void *), void *arg) { int rv; + thr->func = fn; + thr->arg = arg; + // POSIX wants functions to return a void *, but we don't care. - if ((rv = pthread_create(&thr->tid, NULL, (void *) fn, arg)) != 0) { + rv = pthread_create(&thr->tid, NULL, nni_plat_thr_main, thr); + if (rv != 0) { //nni_printf("pthread_create: %s", strerror(rv)); return (NNG_ENOMEM); } -- cgit v1.2.3-70-g09d2