block signals in ddsrt_thread_create

Signal handling in multi-threaded processes is bad enough at the best of
times, and as we don't really use any signals in the Cyclone code, it
makes more sense to create all threads with most signals blocked.  That
way an application that wants to handle signals using sigwait() need not
block all signals prior to creating a participant.

Note that instead of blocking all signals, we block all except SIGXCPU.
The reason is that the liveliness monitoring and stack trace dumping
code currently relies on that signal.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2019-04-15 10:49:51 +02:00 committed by eboasson
parent 0202039f61
commit 31b8baa03b

View file

@ -193,6 +193,7 @@ ddsrt_thread_create (
thread_context_t *ctx; thread_context_t *ctx;
ddsrt_threadattr_t tattr; ddsrt_threadattr_t tattr;
int result, create_ret; int result, create_ret;
sigset_t set, oset;
assert (threadptr != NULL); assert (threadptr != NULL);
assert (name != NULL); assert (name != NULL);
@ -281,11 +282,18 @@ ddsrt_thread_create (
strcpy (ctx->name, name); strcpy (ctx->name, name);
ctx->routine = start_routine; ctx->routine = start_routine;
ctx->arg = arg; ctx->arg = arg;
/* Block signal delivery in our own threads (SIGXCPU is excluded so we have a way of
dumping stack traces, but that should be improved upon) */
sigfillset (&set);
sigdelset (&set, SIGXCPU);
sigprocmask (SIG_BLOCK, &set, &oset);
if ((create_ret = pthread_create (&threadptr->v, &attr, os_startRoutineWrapper, ctx)) != 0) if ((create_ret = pthread_create (&threadptr->v, &attr, os_startRoutineWrapper, ctx)) != 0)
{ {
DDS_ERROR ("os_threadCreate(%s): pthread_create failed with error %d\n", name, create_ret); DDS_ERROR ("os_threadCreate(%s): pthread_create failed with error %d\n", name, create_ret);
goto err_create; goto err_create;
} }
sigprocmask (SIG_SETMASK, &oset, NULL);
pthread_attr_destroy (&attr); pthread_attr_destroy (&attr);
return DDS_RETCODE_OK; return DDS_RETCODE_OK;