From f51d84eac11907346fa02e33da358aad171ac80a Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 27 May 2010 12:01:12 -0400 Subject: [PATCH] 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. --- libust/tracectl.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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; } -- 2.34.1