tfork/test: ensure all threads start with SIGCHLD unblocked
authorRalph Boehme <slow@samba.org>
Mon, 19 Nov 2018 15:47:33 +0000 (16:47 +0100)
committerRalph Boehme <slow@samba.org>
Wed, 28 Nov 2018 11:59:27 +0000 (12:59 +0100)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/tests/tfork.c

index 3c73355b3f092c0256379c3a6136c4afb957dbd9..a74f7e8d7e2de853415965f3561d5a9213506774 100644 (file)
@@ -470,12 +470,29 @@ static bool test_tfork_threads(struct torture_context *tctx)
        bool ok = true;
        const int num_threads = 64;
        pthread_t threads[num_threads];
+       sigset_t set;
        int i;
 
 #ifndef HAVE_PTHREAD
        torture_skip(tctx, "no pthread support\n");
 #endif
 
+       /*
+        * Be nasty and taste for the worst case: ensure all threads start with
+        * SIGCHLD unblocked so we have the most fun with SIGCHLD being
+        * delivered to a random thread. :)
+        */
+       sigemptyset(&set);
+       sigaddset(&set, SIGCHLD);
+#ifdef HAVE_PTHREAD
+       ret = pthread_sigmask(SIG_UNBLOCK, &set, NULL);
+#else
+       ret = sigprocmask(SIG_UNBLOCK, &set, NULL);
+#endif
+       if (ret != 0) {
+               return -1;
+       }
+
        for (i = 0; i < num_threads; i++) {
                ret = pthread_create(&threads[i], NULL, tfork_thread, NULL);
                torture_assert_goto(tctx, ret == 0, ok, done,