nptl: Fix tst-cancel7 and tst-cancelx7 pidfile race
authorStafford Horne <shorne@gmail.com>
Sat, 16 Oct 2021 22:41:54 +0000 (07:41 +0900)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 18 Oct 2021 16:30:10 +0000 (13:30 -0300)
The check for waiting for the pidfile to be created looks wrong.  At the
point when ACCESS is run the pid file will always be created and
accessible as it is created during DO_PREPARE.  This means that thread
cancellation may be performed before the pid is written to the pidfile.

This was found to be flaky when testing on my OpenRISC platform.

Fix this by using the semaphore to wait for pidfile pid write
completion.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
nptl/tst-cancel7.c

index 54ed2a5..e926f44 100644 (file)
@@ -115,16 +115,13 @@ do_test (void)
 {
   pthread_t th = xpthread_create (NULL, tf, NULL);
 
-  do
-    nanosleep (&(struct timespec) { .tv_sec = 0, .tv_nsec = 100000000 }, NULL);
-  while (access (pidfilename, R_OK) != 0);
+  /* Wait to cancel until after the pid is written.  */
+  if (sem_wait (sem) != 0)
+    FAIL_EXIT1 ("sem_wait: %m");
 
   xpthread_cancel (th);
   void *r = xpthread_join (th);
 
-  if (sem_wait (sem) != 0)
-    FAIL_EXIT1 ("sem_wait: %m");
-
   FILE *f = xfopen (pidfilename, "r+");
 
   long long ll;