2016-06-10 13:03:04 +00:00
|
|
|
/* Check sendmmsg cancellation.
|
|
|
|
|
2017-01-01 00:14:16 +00:00
|
|
|
Copyright (C) 2016-2017 Free Software Foundation, Inc.
|
2016-06-10 13:03:04 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
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, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2017-02-16 22:31:42 +00:00
|
|
|
#include <stddef.h>
|
2016-06-10 13:03:04 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/msg.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include "tst-cancel4-common.h"
|
|
|
|
|
|
|
|
static void *
|
|
|
|
tf_sendmmsg (void *arg)
|
|
|
|
{
|
|
|
|
if (arg == NULL)
|
|
|
|
// XXX If somebody can provide a portable test case in which sendmmsg()
|
|
|
|
// 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)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
int tries = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (++tries > 10)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("too many unsuccessful bind calls");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
|
|
|
|
if (mktemp (sun.sun_path) == NULL)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("cannot generate temp file name");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
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)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
int r = pthread_barrier_wait (&b2);
|
|
|
|
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("pthread_barrier_wait");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
r = pthread_barrier_wait (&b2);
|
|
|
|
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("pthread_barrier_wait");
|
2016-06-10 13:03:04 +00:00
|
|
|
|
|
|
|
pthread_cleanup_push (cl, NULL);
|
|
|
|
|
|
|
|
char mem[1];
|
|
|
|
struct iovec iov[1];
|
|
|
|
iov[0].iov_base = mem;
|
|
|
|
iov[0].iov_len = 1;
|
|
|
|
|
|
|
|
struct mmsghdr mm;
|
|
|
|
mm.msg_hdr.msg_name = &sun;
|
|
|
|
mm.msg_hdr.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
|
|
|
|
+ strlen (sun.sun_path) + 1);
|
|
|
|
mm.msg_hdr.msg_iov = iov;
|
|
|
|
mm.msg_hdr.msg_iovlen = 1;
|
|
|
|
mm.msg_hdr.msg_control = NULL;
|
|
|
|
mm.msg_hdr.msg_controllen = 0;
|
|
|
|
|
|
|
|
ssize_t ret = sendmmsg (tempfd2, &mm, 1, 0);
|
|
|
|
if (ret == -1 && errno == ENOSYS)
|
|
|
|
exit (77);
|
|
|
|
|
|
|
|
pthread_cleanup_pop (0);
|
|
|
|
|
2017-04-25 21:56:46 +00:00
|
|
|
FAIL_EXIT1 ("sendmmsg returned");
|
2016-06-10 13:03:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct cancel_tests tests[] =
|
|
|
|
{
|
|
|
|
ADD_TEST (sendmmsg, 2, 1),
|
|
|
|
};
|
|
|
|
#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
|
|
|
|
|
|
|
|
#include "tst-cancel4-common.c"
|