From: Pierre-Marc Fournier Date: Thu, 27 May 2010 16:01:12 +0000 (-0400) Subject: block all signals in listener thread X-Git-Tag: v0.5~14 X-Git-Url: http://git.lttng.org/?p=ust.git;a=commitdiff_plain;h=f51d84eac11907346fa02e33da358aad171ac80a block all signals in listener thread Not doing this can result in a situation where all the other application threads have a signal blocked, and the listener thread, not having it blocked, lets the signal handler execute. Therefore, in order to be as transparent as possible to the application, we have to block signals. --- diff --git a/libust/tracectl.c b/libust/tracectl.c index 3624b86..7a5cf95 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -1031,17 +1032,38 @@ static pthread_t listener_thread; void create_listener(void) { int result; + sigset_t sig_all_blocked; + sigset_t orig_parent_mask; if(have_listener) { WARN("not creating listener because we already had one"); return; } + /* A new thread created by pthread_create inherits the signal mask + * from the parent. To avoid any signal being received by the + * listener thread, we block all signals temporarily in the parent, + * while we create the listener thread. + */ + + sigfillset(&sig_all_blocked); + + result = pthread_sigmask(SIG_SETMASK, &sig_all_blocked, &orig_parent_mask); + if(result) { + PERROR("pthread_sigmask: %s", strerror(result)); + } + result = pthread_create(&listener_thread, NULL, listener_main, NULL); if(result == -1) { PERROR("pthread_create"); } + /* Restore original signal mask in parent */ + result = pthread_sigmask(SIG_SETMASK, &orig_parent_mask, NULL); + if(result) { + PERROR("pthread_sigmask: %s", strerror(result)); + } + have_listener = 1; }