diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-06-17 22:40:05 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-06-17 22:40:05 +0000 |
commit | f23b30e23b93d55dfa6f11e8eaa7f0f9dd492d93 (patch) | |
tree | 21ec8f3fd1769e3bf02b158288c8a1d371539311 /nptl | |
parent | 60d73a7ac4e0116ef2e458d705aeee14aff7aed9 (diff) | |
download | glibc-f23b30e23b93d55dfa6f11e8eaa7f0f9dd492d93.tar.gz |
Update.
2003-06-17 Jakub Jelinek <jakub@redhat.com>
* posix/regcomp.c (build_word_op): Use alnum instead of alpha class.
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 15 | ||||
-rw-r--r-- | nptl/Makefile | 8 | ||||
-rw-r--r-- | nptl/tst-cancel18.c | 174 | ||||
-rw-r--r-- | nptl/tst-cancel4.c | 546 | ||||
-rw-r--r-- | nptl/tst-cancelx18.c | 1 |
5 files changed, 678 insertions, 66 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 744ac3573c..9a4670d3bd 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,5 +1,20 @@ 2003-06-17 Ulrich Drepper <drepper@redhat.com> + * Makefile: Add rules to build and run tst-cancel18 and tst-cancelx18. + * tst-cancel18.c: New file. + * tst-cancelx18.c: New file. + + * tst-cancel4.c: Test connect, creat, msgrcv, msgsnd, sendmsg, sendto, + and tcdrain. + + * Makefile: Add rules to build and run tst-cancel17 and tst-cancel17x. + * tst-cancel17.c: New file. + * tst-cancelx17.c: New file. + + * sysdeps/unix/sysv/linux/sigtimedwait.c: New file. + * sysdeps/unix/sysv/linux/sigwait.c: New file. + * sysdeps/unix/sysv/linux/sigwaitinfo.c: New file. + * tst-cancel4.c: Test open, close, pread, pwrite, fsync, and msync. 2003-06-16 Jakub Jelinek <jakub@redhat.com> diff --git a/nptl/Makefile b/nptl/Makefile index 47717e7a37..fab063dbcb 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -212,7 +212,7 @@ tests = tst-attr1 tst-attr2 \ tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \ tst-cancel6 tst-cancel7 tst-cancel8 tst-cancel9 tst-cancel10 \ tst-cancel11 tst-cancel12 tst-cancel13 tst-cancel14 tst-cancel15 \ - tst-cancel16 tst-cancel17 \ + tst-cancel16 tst-cancel17 tst-cancel18 \ tst-cleanup0 tst-cleanup1 tst-cleanup2 tst-cleanup3 \ tst-flock1 tst-flock2 \ tst-signal1 tst-signal2 tst-signal3 tst-signal4 tst-signal5 \ @@ -243,7 +243,7 @@ ifeq ($(have-forced-unwind),yes) tests += tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx5 \ tst-cancelx6 tst-cancelx7 tst-cancelx8 tst-cancelx9 tst-cancelx10 \ tst-cancelx11 tst-cancelx12 tst-cancelx13 tst-cancelx14 tst-cancelx15\ - tst-cancelx16 tst-cancelx17 \ + tst-cancelx16 tst-cancelx17 tst-cancelx18 \ tst-cleanupx0 tst-cleanupx1 tst-cleanupx2 tst-cleanupx3 endif ifeq ($(build-shared),yes) @@ -388,10 +388,14 @@ ifeq (yes,$(build-shared)) $(objpfx)tst-cond11: $(common-objpfx)rt/librt.so $(objpfx)tst-cancel17: $(common-objpfx)rt/librt.so $(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.so +$(objpfx)tst-cancel18: $(common-objpfx)rt/librt.so +$(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.so else $(objpfx)tst-cond11: $(common-objpfx)rt/librt.a $(objpfx)tst-cancel17: $(common-objpfx)rt/librt.a $(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.a +$(objpfx)tst-cancel18: $(common-objpfx)rt/librt.a +$(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.a endif extra-B-pthread.so = -B$(common-objpfx)nptl/ diff --git a/nptl/tst-cancel18.c b/nptl/tst-cancel18.c new file mode 100644 index 0000000000..15e9ddfbbc --- /dev/null +++ b/nptl/tst-cancel18.c @@ -0,0 +1,174 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + + +static pthread_barrier_t b; + + +/* Cleanup handling test. */ +static int cl_called; + +static void +cl (void *arg) +{ + ++cl_called; +} + + +static void * +tf (void *arg) +{ + int r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 }; + TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts)); + + pthread_cleanup_pop (0); + + puts ("clock_nanosleep returned"); + + exit (1); +} + + +static int +do_test (void) +{ + if (pthread_barrier_init (&b, NULL, 2) != 0) + { + puts ("barrier_init failed"); + return 1; + } + + pthread_t th; + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("1st create failed"); + return 1; + } + + int r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 }; + while (nanosleep (&ts, &ts) != 0) + continue; + + puts ("going to cancel in-time"); + if (pthread_cancel (th) != 0) + { + puts ("1st cancel failed"); + return 1; + } + + void *status; + if (pthread_join (th, &status) != 0) + { + puts ("1st join failed"); + return 1; + } + if (status != PTHREAD_CANCELED) + { + puts ("1st thread not canceled"); + return 1; + } + + if (cl_called == 0) + { + puts ("cleanup handler not called"); + return 1; + } + if (cl_called > 1) + { + puts ("cleanup handler called more than once"); + return 1; + } + + puts ("in-time cancellation succeeded"); + + + cl_called = 0; + + if (pthread_create (&th, NULL, tf, NULL) != 0) + { + puts ("2nd create failed"); + return 1; + } + + puts ("going to cancel early"); + if (pthread_cancel (th) != 0) + { + puts ("2nd cancel failed"); + return 1; + } + + r = pthread_barrier_wait (&b); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + puts ("barrier_wait failed"); + exit (1); + } + + if (pthread_join (th, &status) != 0) + { + puts ("2nd join failed"); + return 1; + } + if (status != PTHREAD_CANCELED) + { + puts ("2nd thread not canceled"); + return 1; + } + + if (cl_called == 0) + { + printf ("cleanup handler not called\n"); + return 1; + } + if (cl_called > 1) + { + printf ("cleanup handler called more than once\n"); + return 1; + } + + puts ("early cancellation succeeded"); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/nptl/tst-cancel4.c b/nptl/tst-cancel4.c index fa25c478d7..d729de6384 100644 --- a/nptl/tst-cancel4.c +++ b/nptl/tst-cancel4.c @@ -28,8 +28,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <termios.h> #include <unistd.h> #include <sys/mman.h> +#include <sys/msg.h> #include <sys/poll.h> #include <sys/select.h> #include <sys/socket.h> @@ -40,17 +42,9 @@ #include "pthreadP.h" -/* The following interfaces are defined to be cancellation points but - tests are not yet implemented: - - aio_suspend() clock_nanosleep() - connect() creat() - msgrcv() msgsnd() - sendmsg() sendto() - tcdrain() - - Since STREAMS are not supported in the standard Linux kernel there - is no need to test the STREAMS related functions. This affects +/* Since STREAMS are not supported in the standard Linux kernel and + there we don't advertise STREAMS as supported is no need to test + the STREAMS related functions. This affects getmsg() getpmsg() putmsg() putpmsg() @@ -65,6 +59,10 @@ POSIX message queues aren't implemented yet. This affects mq_receive() mq_send() mq_timedreceive() mq_timedsend() + + aio_suspend() is tested in tst-cancel17. + + clock_nanosleep() is tested in tst-cancel18. */ /* Pipe descriptors. */ @@ -75,6 +73,8 @@ static int tempfd = -1; static int tempfd2 = -1; /* Name of temporary file to be removed after each round. */ static char *tempfname; +/* Temporary message queue. */ +static int tempmsg = -1; /* Often used barrier for two threads. */ static pthread_barrier_t b2; @@ -121,15 +121,16 @@ tf_read (void *arg) exit (1); } + ssize_t s; pthread_cleanup_push (cl, NULL); char buf[100]; - ssize_t s = read (fd, buf, sizeof (buf)); - - printf ("%s: read returns with %zd\n", __FUNCTION__, s); + s = read (fd, buf, sizeof (buf)); pthread_cleanup_pop (0); + printf ("%s: read returns with %zd\n", __FUNCTION__, s); + exit (1); } @@ -165,16 +166,17 @@ tf_readv (void *arg) exit (1); } + ssize_t s; pthread_cleanup_push (cl, NULL); char buf[100]; struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } }; - ssize_t s = readv (fd, iov, 1); - - printf ("%s: readv returns with %zd\n", __FUNCTION__, s); + s = readv (fd, iov, 1); pthread_cleanup_pop (0); + printf ("%s: readv returns with %zd\n", __FUNCTION__, s); + exit (1); } @@ -210,16 +212,17 @@ tf_write (void *arg) exit (1); } + ssize_t s; pthread_cleanup_push (cl, NULL); char buf[100000]; memset (buf, '\0', sizeof (buf)); - ssize_t s = write (fd, buf, sizeof (buf)); - - printf ("%s: write returns with %zd\n", __FUNCTION__, s); + s = write (fd, buf, sizeof (buf)); pthread_cleanup_pop (0); + printf ("%s: write returns with %zd\n", __FUNCTION__, s); + exit (1); } @@ -255,17 +258,18 @@ tf_writev (void *arg) exit (1); } + ssize_t s; pthread_cleanup_push (cl, NULL); char buf[100000]; memset (buf, '\0', sizeof (buf)); struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } }; - ssize_t s = writev (fd, iov, 1); - - printf ("%s: writev returns with %zd\n", __FUNCTION__, s); + s = writev (fd, iov, 1); pthread_cleanup_pop (0); + printf ("%s: writev returns with %zd\n", __FUNCTION__, s); + exit (1); } @@ -357,8 +361,7 @@ tf_nanosleep (void *arg) pthread_cleanup_push (cl, NULL); struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 }; - while (nanosleep (&ts, &ts) != 0) - continue; + TEMP_FAILURE_RETRY (nanosleep (&ts, &ts)); pthread_cleanup_pop (0); @@ -403,15 +406,16 @@ tf_select (void *arg) FD_ZERO (&rfs); FD_SET (fd, &rfs); + int s; pthread_cleanup_push (cl, NULL); - int s = select (fd + 1, &rfs, NULL, NULL, NULL); + s = select (fd + 1, &rfs, NULL, NULL, NULL); + + pthread_cleanup_pop (0); printf ("%s: select returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -451,15 +455,16 @@ tf_pselect (void *arg) FD_ZERO (&rfs); FD_SET (fd, &rfs); + int s; pthread_cleanup_push (cl, NULL); - int s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL); + s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL); + + pthread_cleanup_pop (0); printf ("%s: pselect returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -497,15 +502,16 @@ tf_poll (void *arg) struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } }; + int s; pthread_cleanup_push (cl, NULL); - int s = poll (rfs, 1, -1); + s = poll (rfs, 1, -1); + + pthread_cleanup_pop (0); printf ("%s: poll returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -550,15 +556,16 @@ tf_wait (void *arg) exit (1); } + int s; pthread_cleanup_push (cl, NULL); - int s = wait (NULL); + s = wait (NULL); + + pthread_cleanup_pop (0); printf ("%s: wait returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -604,15 +611,16 @@ tf_waitpid (void *arg) exit (1); } + int s; pthread_cleanup_push (cl, NULL); - int s = waitpid (-1, NULL, 0); + s = waitpid (-1, NULL, 0); + + pthread_cleanup_pop (0); printf ("%s: waitpid returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -657,16 +665,17 @@ tf_waitid (void *arg) exit (1); } + int s; pthread_cleanup_push (cl, NULL); siginfo_t si; - int s = waitid (P_PID, pid, &si, 0); + s = waitid (P_PID, pid, &si, 0); + + pthread_cleanup_pop (0); printf ("%s: waitid returns with %d (%s)\n", __FUNCTION__, s, strerror (errno)); - pthread_cleanup_pop (0); - exit (1); } @@ -760,8 +769,6 @@ tf_sigwait (void *arg) } } - pthread_cleanup_push (cl, NULL); - /* Block SIGUSR1. */ sigset_t mask; sigaddset (&mask, SIGUSR1); @@ -771,14 +778,16 @@ tf_sigwait (void *arg) exit (1); } - /* Wait for SIGUSR1. */ int sig; - sigwait (&mask, &sig); + pthread_cleanup_push (cl, NULL); - printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig); + /* Wait for SIGUSR1. */ + sigwait (&mask, &sig); pthread_cleanup_pop (0); + printf ("%s: sigwait returned with signal %d\n", __FUNCTION__, sig); + exit (1); } @@ -803,8 +812,6 @@ tf_sigwaitinfo (void *arg) } } - pthread_cleanup_push (cl, NULL); - /* Block SIGUSR1. */ sigset_t mask; sigaddset (&mask, SIGUSR1); @@ -814,15 +821,17 @@ tf_sigwaitinfo (void *arg) exit (1); } - /* Wait for SIGUSR1. */ siginfo_t info; + pthread_cleanup_push (cl, NULL); + + /* Wait for SIGUSR1. */ sigwaitinfo (&mask, &info); + pthread_cleanup_pop (0); + printf ("%s: sigwaitinfo returned with signal %d\n", __FUNCTION__, info.si_signo); - pthread_cleanup_pop (0); - exit (1); } @@ -847,8 +856,6 @@ tf_sigtimedwait (void *arg) } } - pthread_cleanup_push (cl, NULL); - /* Block SIGUSR1. */ sigset_t mask; sigaddset (&mask, SIGUSR1); @@ -861,13 +868,15 @@ tf_sigtimedwait (void *arg) /* Wait for SIGUSR1. */ siginfo_t info; struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 }; + pthread_cleanup_push (cl, NULL); + sigtimedwait (&mask, &info, &ts); + pthread_cleanup_pop (0); + printf ("%s: sigtimedwait returned with signal %d\n", __FUNCTION__, info.si_signo); - pthread_cleanup_pop (0); - exit (1); } @@ -927,7 +936,7 @@ tf_accept (void *arg) printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); } - strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-XXXXXX"); + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX"); if (mktemp (sun.sun_path) == NULL) { printf ("%s: cannot generate temp file name\n", __FUNCTION__); @@ -995,7 +1004,7 @@ tf_send (void *arg) printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); } - strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-XXXXXX"); + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX"); if (mktemp (sun.sun_path) == NULL) { printf ("%s: cannot generate temp file name\n", __FUNCTION__); @@ -1077,7 +1086,7 @@ tf_recv (void *arg) printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); } - strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-XXXXXX"); + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX"); if (mktemp (sun.sun_path) == NULL) { printf ("%s: cannot generate temp file name\n", __FUNCTION__); @@ -1158,7 +1167,7 @@ tf_recvfrom (void *arg) printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); } - strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-XXXXXX"); + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX"); if (mktemp (sun.sun_path) == NULL) { printf ("%s: cannot generate temp file name\n", __FUNCTION__); @@ -1233,7 +1242,7 @@ tf_recvmsg (void *arg) printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); } - strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-XXXXXX"); + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX"); if (mktemp (sun.sun_path) == NULL) { printf ("%s: cannot generate temp file name\n", __FUNCTION__); @@ -1548,6 +1557,399 @@ tf_msync (void *arg) } +static void * +tf_sendto (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendto() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[1]; + + sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, + (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1); + + pthread_cleanup_pop (0); + + printf ("%s: sendto returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_sendmsg (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendmsg() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + char mem[1]; + struct iovec iov[1]; + iov[0].iov_base = mem; + iov[0].iov_len = 1; + + struct msghdr m; + m.msg_name = &sun; + m.msg_namelen = (offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1); + m.msg_iov = iov; + m.msg_iovlen = 1; + m.msg_control = NULL; + m.msg_controllen = 0; + + sendmsg (tempfd2, &m, 0); + + pthread_cleanup_pop (0); + + printf ("%s: sendmsg returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_creat (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which sendmsg() + // blocks we can enable this test to run in both rounds. + abort (); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + creat ("tmp/tst-cancel-4-should-not-exist", 0666); + + pthread_cleanup_pop (0); + + printf ("%s: creat returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_connect (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which connect() + // blocks we can enable this test to run in both rounds. + abort (); + + struct sockaddr_un sun; + + tempfd = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd == -1) + { + printf ("%s: first socket call failed\n", __FUNCTION__); + exit (1); + } + + int tries = 0; + do + { + if (++tries > 10) + { + printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); + } + + strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX"); + if (mktemp (sun.sun_path) == NULL) + { + printf ("%s: cannot generate temp file name\n", __FUNCTION__); + exit (1); + } + + sun.sun_family = AF_UNIX; + } + while (bind (tempfd, (struct sockaddr *) &sun, + offsetof (struct sockaddr_un, sun_path) + + strlen (sun.sun_path) + 1) != 0); + tempfname = strdup (sun.sun_path); + + listen (tempfd, 5); + + tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0); + if (tempfd2 == -1) + { + printf ("%s: second socket call failed\n", __FUNCTION__); + exit (1); + } + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)); + + pthread_cleanup_pop (0); + + printf ("%s: connect returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_tcdrain (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which tcdrain() + // blocks we can enable this test to run in both rounds. + abort (); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + /* Regardless of stderr being a terminal, the tcdrain call should be + canceled. */ + tcdrain (STDERR_FILENO); + + pthread_cleanup_pop (0); + + printf ("%s: tcdrain returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_msgrcv (void *arg) +{ + tempmsg = msgget (random (), 0666 | IPC_CREAT); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + if (arg != NULL) + { + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + } + + pthread_cleanup_push (cl, NULL); + + struct + { + long int type; + char mem[10]; + } m; + msgrcv (tempmsg, (struct msgbuf *) &m, 10, 100, 0); + + pthread_cleanup_pop (0); + + printf ("%s: msgrcv returned\n", __FUNCTION__); + + exit (1); +} + + +static void * +tf_msgsnd (void *arg) +{ + if (arg == NULL) + // XXX If somebody can provide a portable test case in which msgsnd() + // blocks we can enable this test to run in both rounds. + abort (); + + tempmsg = msgget (random (), 0666 | IPC_CREAT); + + int r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + r = pthread_barrier_wait (&b2); + if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) + { + printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); + exit (1); + } + + pthread_cleanup_push (cl, NULL); + + struct + { + long int type; + char mem[1]; + } m; + m.type = 100; + msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0); + + pthread_cleanup_pop (0); + + printf ("%s: msgsnd returned\n", __FUNCTION__); + + exit (1); +} + + static struct { const char *name; @@ -1587,6 +1989,13 @@ static struct ADD_TEST (pwrite, 2, 1), ADD_TEST (fsync, 2, 1), ADD_TEST (msync, 2, 1), + ADD_TEST (sendto, 2, 1), + ADD_TEST (sendmsg, 2, 1), + ADD_TEST (creat, 2, 1), + ADD_TEST (connect, 2, 1), + ADD_TEST (tcdrain, 2, 1), + ADD_TEST (msgrcv, 2, 0), + ADD_TEST (msgsnd, 2, 1), }; #define ntest_tf (sizeof (tests) / sizeof (tests[0])) @@ -1783,8 +2192,17 @@ do_test (void) close (tempfd2); tempfd2 = -1; } - free (tempfname); - tempfname = NULL; + if (tempfname != NULL) + { + unlink (tempfname); + free (tempfname); + tempfname = NULL; + } + if (tempmsg != -1) + { + msgctl (tempmsg, IPC_RMID, NULL); + tempmsg = -1; + } } return result; diff --git a/nptl/tst-cancelx18.c b/nptl/tst-cancelx18.c new file mode 100644 index 0000000000..56da18f382 --- /dev/null +++ b/nptl/tst-cancelx18.c @@ -0,0 +1 @@ +#include "tst-cancel18.c" |