|
Packit |
6c4009 |
/* Check recvmmsg cancellation.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <stddef.h>
|
|
Packit |
6c4009 |
#include <stdlib.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <sys/types.h>
|
|
Packit |
6c4009 |
#include <sys/socket.h>
|
|
Packit |
6c4009 |
#include <sys/un.h>
|
|
Packit |
6c4009 |
#include <sys/ipc.h>
|
|
Packit |
6c4009 |
#include <sys/msg.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
#include <errno.h>
|
|
Packit |
6c4009 |
#include <pthread.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "tst-cancel4-common.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static void *
|
|
Packit |
6c4009 |
tf_recvmmsg (void *arg)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
struct sockaddr_un sun;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
|
|
Packit |
6c4009 |
if (tempfd == -1)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int tries = 0;
|
|
Packit |
6c4009 |
do
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (++tries > 10)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("too many unsuccessful bind calls");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
|
|
Packit |
6c4009 |
if (mktemp (sun.sun_path) == NULL)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("cannot generate temp file name");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
sun.sun_family = AF_UNIX;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
while (bind (tempfd, (struct sockaddr *) &sun,
|
|
Packit |
6c4009 |
offsetof (struct sockaddr_un, sun_path)
|
|
Packit |
6c4009 |
+ strlen (sun.sun_path) + 1) != 0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
tempfname = strdup (sun.sun_path);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
|
|
Packit |
6c4009 |
if (tempfd2 == -1)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
int r = pthread_barrier_wait (&b2;;
|
|
Packit |
6c4009 |
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("pthread_barrier_wait");
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
if (arg != NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
r = pthread_barrier_wait (&b2;;
|
|
Packit |
6c4009 |
if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("pthread_barrier_wait");
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pthread_cleanup_push (cl, NULL);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
char mem[70];
|
|
Packit |
6c4009 |
struct iovec iov[1];
|
|
Packit |
6c4009 |
iov[0].iov_base = mem;
|
|
Packit |
6c4009 |
iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct mmsghdr mm;
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_name = &sun;
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_namelen = sizeof (sun);
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_iov = iov;
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_iovlen = 1;
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_control = NULL;
|
|
Packit |
6c4009 |
mm.msg_hdr.msg_controllen = 0;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ssize_t ret = recvmmsg (tempfd2, &mm, 1, 0, NULL);
|
|
Packit |
6c4009 |
if (ret == -1 && errno == ENOSYS)
|
|
Packit |
6c4009 |
exit (77);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
pthread_cleanup_pop (0);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
FAIL_EXIT1 ("recvmmsg returned");
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
struct cancel_tests tests[] =
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
ADD_TEST (recvmmsg, 2, 1),
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include "tst-cancel4-common.c"
|