about summary refs log tree commit diff
path: root/nptl/tst-cancel7.c
diff options
context:
space:
mode:
Diffstat (limited to 'nptl/tst-cancel7.c')
-rw-r--r--nptl/tst-cancel7.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/nptl/tst-cancel7.c b/nptl/tst-cancel7.c
index d2350bde20..3f874c2a3c 100644
--- a/nptl/tst-cancel7.c
+++ b/nptl/tst-cancel7.c
@@ -38,6 +38,8 @@ static char *semfilename;
 
 static sem_t *sem;
 
+static void do_cleanup (void);
+
 static void *
 tf (void *arg)
 {
@@ -57,9 +59,6 @@ sl (void)
   fprintf (f, "%lld\n", (long long) getpid ());
   fflush (f);
 
-  if (sem_post (sem) != 0)
-    FAIL_EXIT1 ("sem_post: %m");
-
   struct flock fl =
     {
       .l_type = F_WRLCK,
@@ -70,6 +69,9 @@ sl (void)
   if (fcntl (fileno (f), F_SETLK, &fl) != 0)
     FAIL_EXIT1 ("fcntl (F_SETFL): %m");
 
+  if (sem_post (sem) != 0)
+    FAIL_EXIT1 ("sem_post: %m");
+
   sigset_t ss;
   sigfillset (&ss);
   sigsuspend (&ss);
@@ -108,6 +110,8 @@ do_prepare (int argc, char *argv[])
 
   xwrite (fd, " ", 1);
   xclose (fd);
+
+  atexit (do_cleanup);
 }
 
 
@@ -116,7 +120,7 @@ do_test (void)
 {
   pthread_t th = xpthread_create (NULL, tf, NULL);
 
-  /* Wait to cancel until after the pid is written.  */
+  /* Wait to cancel until after the pid is written and file locked.  */
   if (sem_wait (sem) != 0)
     FAIL_EXIT1 ("sem_wait: %m");