2018-03-03 Adhemerval Zanella <adhemerval.zanella@linaro.org>
+ * nptl/tst-cancel4-common.h (set_socket_buffer): New function.
+ * nptl/tst-cancel4-common.c (do_test): Call set_socket_buffer
+ for socketpair endpoint.
+ * nptl/tst-cancel4.c (tf_send): Call set_socket_buffer and use
+ WRITE_BUFFER_SIZE as buffer size for sending socket.
+ (tf_sendto): Use SOCK_STREAM instead of SOCK_DGRAM and fix an
+ issue on system where send is implemented with sendto syscall.
+ * sysdeps/unix/sysv/linux/mips/mips64/Makefile [$(subdir) = socket]
+ (CFLAGS-recv.c, CFLAGS-send.c): Remove rules.
+ [$(subdir) = nptl] (CFLAGS-recv.c, CFLAGS-send.c): Likewise.
+ * sysdeps/unix/sysv/linux/riscv/rv64/Makefile: Remove file.
+
[BZ #21269]
* sysdeps/unix/sysv/linux/i386/Makefile (tests): Add tst-bz21269.
* sysdeps/unix/sysv/linux/i386/sigaction.c (SET_SA_RESTORER): Clear
static int
do_test (void)
{
- int val;
- socklen_t len;
-
if (socketpair (AF_UNIX, SOCK_STREAM, PF_UNIX, fds) != 0)
{
perror ("socketpair");
exit (1);
}
- val = 1;
- len = sizeof(val);
- setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
- if (getsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, &len) < 0)
- {
- perror ("getsockopt");
- exit (1);
- }
- if (val >= WRITE_BUFFER_SIZE)
- {
- puts ("minimum write buffer size too large");
- exit (1);
- }
- setsockopt (fds[1], SOL_SOCKET, SO_SNDBUF, &val, sizeof(val));
+ set_socket_buffer (fds[1]);
if (mktemp (fifoname) == NULL)
{
#define WRITE_BUFFER_SIZE 16384
+/* Set the send buffer of socket S to 1 byte so any send operation
+ done with WRITE_BUFFER_SIZE bytes will force syscall blocking. */
+static void
+set_socket_buffer (int s)
+{
+ int val = 1;
+ socklen_t len = sizeof(val);
+
+ TEST_VERIFY_EXIT (setsockopt (s, SOL_SOCKET, SO_SNDBUF, &val,
+ sizeof(val)) == 0);
+ TEST_VERIFY_EXIT (getsockopt (s, SOL_SOCKET, SO_SNDBUF, &val, &len) == 0);
+ TEST_VERIFY_EXIT (val < WRITE_BUFFER_SIZE);
+}
+
/* Cleanup handling test. */
static int cl_called;
if (tempfd2 == -1)
FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
+ set_socket_buffer (tempfd2);
+
if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
FAIL_EXIT1 ("connect: %m");
pthread_cleanup_push (cl, NULL);
- /* Very large block, so that the send call blocks. */
- char mem[700000];
+ char mem[WRITE_BUFFER_SIZE];
send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
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);
+ tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
if (tempfd == -1)
- FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+ FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
int tries = 0;
do
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);
+ listen (tempfd, 5);
+
+ tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
if (tempfd2 == -1)
- FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
+ FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
- xpthread_barrier_wait (&b2);
+ set_socket_buffer (tempfd2);
+
+ if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
+ FAIL_EXIT1 ("connect: %m");
+
+ unlink (sun.sun_path);
xpthread_barrier_wait (&b2);
+ if (arg != NULL)
+ xpthread_barrier_wait (&b2);
+
pthread_cleanup_push (cl, NULL);
- char mem[1];
+ char mem[WRITE_BUFFER_SIZE];
- sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
- (struct sockaddr *) &sun,
- offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
+ sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0, NULL, 0);
pthread_cleanup_pop (0);