aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-01-12 21:26:59 -0800
committerGarrett D'Amore <garrett@damore.org>2017-01-12 21:26:59 -0800
commitda88419ae8165248621cad26df72a0d91663d50b (patch)
treea10598f198797060210f586780a91bd6dd920ab0 /src
parentd615c5e51268a23887e2d29b5828a0447ba5409b (diff)
downloadnng-da88419ae8165248621cad26df72a0d91663d50b.tar.gz
nng-da88419ae8165248621cad26df72a0d91663d50b.tar.bz2
nng-da88419ae8165248621cad26df72a0d91663d50b.zip
Block SIGPIPE. Ewww...
Diffstat (limited to 'src')
-rw-r--r--src/platform/posix/posix_impl.h4
-rw-r--r--src/platform/posix/posix_thread.c23
2 files changed, 25 insertions, 2 deletions
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 <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
+#include <signal.h>
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);
}