From patchwork Tue Jan 12 19:23:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 10351 Received: (qmail 44204 invoked by alias); 12 Jan 2016 19:24:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 44195 invoked by uid 89); 12 Jan 2016 19:24:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.0 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=Mask, ensuring, 1167, U*murphyp X-HELO: e37.co.us.ibm.com X-IBM-Helo: d03dlp01.boulder.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com X-IBM-RcptTo: libc-alpha@sourceware.org To: "libc-alpha@sourceware.org" Cc: Adhemerval Zanella , Tulio Magno Quites Machado Filho From: "Paul E. Murphy" Subject: Fix race in tst-mqueue5 Message-ID: <569552C6.8050200@linux.vnet.ibm.com> Date: Tue, 12 Jan 2016 13:23:50 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16011219-0025-0000-0000-000020565DB6 This seems to fix the test for ppc, and probably others too. From 49d281b08a871cb5835b2ca166082821ea0e9085 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Mon, 11 Jan 2016 17:24:04 -0500 Subject: [PATCH] Fix race in tst-mqueue5 The check is done on line 117 by a thread spawned from do_child(), forked from do_test(). This test generates a signal in the forked process. Either thread may handle the signal, and on ppc, it happens to be done on do_child, on the thread which is not doing the check on line 117. This exposes a race condition whereby the test incorrectly fails as the signal is caught during or after the check. This is mitigated by ensuring the signal is blocked in the child thread while thread is running. 2016-01-11 Paul E. Murphy * rt/tst-mqueue5.c (thr): Cleanup misleading comment. (do_child): Mask SIGRTMIN while thr is running. --- rt/tst-mqueue5.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/rt/tst-mqueue5.c b/rt/tst-mqueue5.c index aa74fa3..25042bc 100644 --- a/rt/tst-mqueue5.c +++ b/rt/tst-mqueue5.c @@ -116,7 +116,7 @@ thr (void *arg) if (rtmin_cnt != 2) { - puts ("SIGRTMIN signal in child did not arrive"); + puts ("SIGRTMIN signal in thread did not arrive"); result = 1; } else if (rtmin_pid != getppid () @@ -403,6 +403,16 @@ do_child (const char *name, pthread_barrier_t *b2, pthread_barrier_t *b3, result = 1; } + /* Ensure the thr thread gets the signal, not us. */ + sigset_t set; + sigemptyset (&set); + sigaddset (&set, SIGRTMIN); + if (pthread_sigmask (SIG_BLOCK, &set, NULL)) + { + printf ("Failed to block SIGRTMIN in child: %m\n"); + result = 1; + } + (void) pthread_barrier_wait (b2); /* Parent calls mqsend (q), which should wake up mqrecv (q) @@ -514,7 +524,14 @@ do_child (const char *name, pthread_barrier_t *b2, pthread_barrier_t *b3, result = 1; } - void *thr_ret; + /* Reenable test signals before cleaning up the thread. */ + if (pthread_sigmask (SIG_UNBLOCK, &set, NULL)) + { + printf ("Failed to unblock SIGRTMIN in child: %m\n"); + result = 1; + } + + void *thr_ret; ret = pthread_join (th, &thr_ret); if (ret) { -- 2.4.3