summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul E. Murphy <murphyp@linux.vnet.ibm.com>2016-01-19 13:42:44 -0600
committerTulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>2016-01-22 14:21:03 -0200
commitfad7e4d70665a228f23761cdffe5da674ca768be (patch)
tree3dbe6a99840229ad79f5eb182487f2d555efee90
parentaf8ea0f449af7d3847351a4a5bafcd435a22ac31 (diff)
downloadglibc-fad7e4d70665a228f23761cdffe5da674ca768be.tar.gz
glibc-fad7e4d70665a228f23761cdffe5da674ca768be.tar.xz
glibc-fad7e4d70665a228f23761cdffe5da674ca768be.zip
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.
-rw-r--r--ChangeLog7
-rw-r--r--nptl/tst-setuid3.c18
2 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index b07621be9e..9418e262cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2016-01-22  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
 
+	* 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.
+
+2016-01-22  Paul E. Murphy  <murphyp@linux.vnet.ibm.com>
+
 	* sysdeps/unix/sysv/linux/powerpc/htm.h	(__libc_tbegin): Remove
 	semicolon.
 	(__libc_tend): Likewise.
diff --git a/nptl/tst-setuid3.c b/nptl/tst-setuid3.c
index e017934f8b..40dbb2a62c 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;