From patchwork Tue Jan 19 23:31:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 10478 Received: (qmail 36966 invoked by alias); 19 Jan 2016 23:31:34 -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 36955 invoked by uid 89); 19 Jan 2016 23:31:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=shutdown, charm, 243 X-HELO: e34.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 Subject: Re: [PATCH] Fix nptl/tst-setuid3.c To: Florian Weimer , Adhemerval Zanella References: <569E97E2.1000307@linux.vnet.ibm.com> <569E99CF.3020504@redhat.com> <569E9AA0.3070208@linaro.org> <569E9D4A.8050108@linux.vnet.ibm.com> <569E9DB4.9080205@redhat.com> Cc: "libc-alpha@sourceware.org" , Tulio Magno Quites Machado Filho From: "Paul E. Murphy" Message-ID: <569EC74C.7000301@linux.vnet.ibm.com> Date: Tue, 19 Jan 2016 17:31:24 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <569E9DB4.9080205@redhat.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16011923-0017-0000-0000-0000115007F2 On 01/19/2016 02:33 PM, Florian Weimer wrote: > On 01/19/2016 09:32 PM, Paul E. Murphy wrote: >> +/* True if pthread_barrier_wait returns without an error. */ >> +static inline bool >> +is_invalid_barrier_ret (int x) >> +{ >> + return x != 0 && x != PTHREAD_BARRIER_SERIAL_THREAD; >> +} > > Sorry, just realized that the comment is wrong, should be “returned > *with* an error”. :-/ Thanks for point that out. Sigh, third time is a charm? I rewrote the comment. > Otherwise, still okay from my point of view. > > Florian > From e1d9083bc36a707ffcea6df9fd2b432c60f10122 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Tue, 19 Jan 2016 13:42:44 -0600 Subject: [PATCH] Fix nptl/tst-setuid3.c pthread_barrier_wait can return either PTHREAD_BARRIER_SERIAL_THREAD or 0. Posix makes no guarantees about which thread return the unique value. Additionally, pthread_join was not called despite seemingly checking for the error. 2016-01-19 Paul E. Murphy * nptl/tst-setuid3.c (is_invalid_barrier_ret): New function. (thread_func): Use new function to simplify barrier check. (do_test): Use new function to simplify checking barrier exit code, and actually join the child thread. --- nptl/tst-setuid3.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/nptl/tst-setuid3.c b/nptl/tst-setuid3.c index e017934..40dbb2a 100644 --- a/nptl/tst-setuid3.c +++ b/nptl/tst-setuid3.c @@ -33,14 +33,21 @@ static pthread_barrier_t barrier2; #define FAIL_ERR(fmt, ...) \ do { printf ("FAIL: " fmt ": %m\n", __VA_ARGS__); _exit (1); } while (0) +/* True if x is not a successful return code from pthread_barrier_wait. */ +static inline bool +is_invalid_barrier_ret (int x) +{ + return x != 0 && x != PTHREAD_BARRIER_SERIAL_THREAD; +} + static void * thread_func (void *ctx __attribute__ ((unused))) { int ret = pthread_barrier_wait (&barrier1); - if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0) + if (is_invalid_barrier_ret (ret)) FAIL ("pthread_barrier_wait (barrier1) (on thread): %d", ret); ret = pthread_barrier_wait (&barrier2); - if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0) + if (is_invalid_barrier_ret (ret)) FAIL ("pthread_barrier_wait (barrier2) (on thread): %d", ret); return NULL; } @@ -86,7 +93,7 @@ do_test (void) /* Ensure that the thread is running properly. */ ret = pthread_barrier_wait (&barrier1); - if (ret != 0) + if (is_invalid_barrier_ret (ret)) FAIL ("pthread_barrier_wait (barrier1): %d", ret); setuid_failure (2); @@ -97,10 +104,11 @@ do_test (void) /* Shutdown. */ ret = pthread_barrier_wait (&barrier2); - if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0) + if (is_invalid_barrier_ret (ret)) FAIL ("pthread_barrier_wait (barrier2): %d", ret); - if (ret != PTHREAD_BARRIER_SERIAL_THREAD && ret != 0) + ret = pthread_join (thread, NULL); + if (ret != 0) FAIL ("pthread_join: %d", ret); return 0; -- 2.4.3