Block signals for the helper thread
authorBart Van Assche <bvanassche@acm.org>
Sat, 4 Jan 2020 21:58:52 +0000 (13:58 -0800)
committerBart Van Assche <bvanassche@acm.org>
Sat, 4 Jan 2020 22:39:41 +0000 (14:39 -0800)
Let another thread than the helper thread handle signals. This simplifies
error handling. As an example, the next patch will check the return value
of select() and won't have to check for EINTR due to this patch.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
configure
helper_thread.c

index 2671c325ce5db04c0824d3c43fae9d62916230c0..fa6df532f0a70092e4fbbcb0e13c6190af3d3e9a 100755 (executable)
--- a/configure
+++ b/configure
@@ -726,6 +726,27 @@ elif compile_prog "" "$LIBS -lpthread" "pthread_condattr_setclock" ; then
 fi
 print_config "pthread_condattr_setclock()" "$pthread_condattr_setclock"
 
+##########################################
+# pthread_sigmask() probe
+if test "$pthread_sigmask" != "yes" ; then
+  pthread_sigmask="no"
+fi
+cat > $TMPC <<EOF
+#include <stddef.h> /* NULL */
+#include <signal.h> /* pthread_sigmask() */
+int main(void)
+{
+  return pthread_sigmask(0, NULL, NULL);
+}
+EOF
+if compile_prog "" "$LIBS" "pthread_sigmask" ; then
+  pthread_sigmask=yes
+elif compile_prog "" "$LIBS -lpthread" "pthread_sigmask" ; then
+  pthread_sigmask=yes
+  LIBS="$LIBS -lpthread"
+fi
+print_config "pthread_sigmask()" "$pthread_sigmask"
+
 ##########################################
 # solaris aio probe
 if test "$solaris_aio" != "yes" ; then
@@ -2534,6 +2555,9 @@ fi
 if test "$pthread_condattr_setclock" = "yes" ; then
   output_sym "CONFIG_PTHREAD_CONDATTR_SETCLOCK"
 fi
+if test "$pthread_sigmask" = "yes" ; then
+  output_sym "CONFIG_PTHREAD_SIGMASK"
+fi
 if test "$have_asprintf" = "yes" ; then
     output_sym "CONFIG_HAVE_ASPRINTF"
 fi
index 28f6cca323d303fc370877610ba65513d509cd39..ad2e83b4e18f8812642683a8358d8a8ccd71d9b1 100644 (file)
@@ -1,3 +1,4 @@
+#include <signal.h>
 #ifdef CONFIG_VALGRIND_DEV
 #include <valgrind/drd.h>
 #else
@@ -137,6 +138,18 @@ static void *helper_thread_main(void *data)
 
        sk_out_assign(hd->sk_out);
 
+#ifdef HAVE_PTHREAD_SIGMASK
+       {
+       sigset_t sigmask;
+
+       /* Let another thread handle signals. */
+       ret = pthread_sigmask(SIG_UNBLOCK, NULL, &sigmask);
+       assert(ret == 0);
+       ret = pthread_sigmask(SIG_BLOCK, &sigmask, NULL);
+       assert(ret == 0);
+       }
+#endif
+
 #ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
        clock_gettime(CLOCK_MONOTONIC, &ts);
 #else