]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-cancel4_1.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / nptl / tst-cancel4_1.c
CommitLineData
b39b6e0c
AZ
1/* Check sendmmsg cancellation.
2
04277e02 3 Copyright (C) 2016-2019 Free Software Foundation, Inc.
b39b6e0c
AZ
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
5a82c748 18 <https://www.gnu.org/licenses/>. */
b39b6e0c
AZ
19
20#include <stdio.h>
ceaa9889 21#include <stddef.h>
b39b6e0c
AZ
22#include <stdlib.h>
23#include <string.h>
24#include <sys/types.h>
25#include <sys/socket.h>
26#include <sys/un.h>
27#include <sys/ipc.h>
28#include <sys/msg.h>
29#include <unistd.h>
30#include <errno.h>
31#include <pthread.h>
32
33#include "tst-cancel4-common.h"
34
35static void *
36tf_sendmmsg (void *arg)
37{
38 if (arg == NULL)
39 // XXX If somebody can provide a portable test case in which sendmmsg()
40 // blocks we can enable this test to run in both rounds.
41 abort ();
42
43 struct sockaddr_un sun;
44
45 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
46 if (tempfd == -1)
fa66f341 47 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
b39b6e0c
AZ
48
49 int tries = 0;
50 do
51 {
52 if (++tries > 10)
fa66f341 53 FAIL_EXIT1 ("too many unsuccessful bind calls");
b39b6e0c
AZ
54
55 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
56 if (mktemp (sun.sun_path) == NULL)
fa66f341 57 FAIL_EXIT1 ("cannot generate temp file name");
b39b6e0c
AZ
58
59 sun.sun_family = AF_UNIX;
60 }
61 while (bind (tempfd, (struct sockaddr *) &sun,
62 offsetof (struct sockaddr_un, sun_path)
63 + strlen (sun.sun_path) + 1) != 0);
64 tempfname = strdup (sun.sun_path);
65
66 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
67 if (tempfd2 == -1)
fa66f341 68 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
b39b6e0c
AZ
69
70 int r = pthread_barrier_wait (&b2);
71 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
fa66f341 72 FAIL_EXIT1 ("pthread_barrier_wait");
b39b6e0c
AZ
73
74 r = pthread_barrier_wait (&b2);
75 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
fa66f341 76 FAIL_EXIT1 ("pthread_barrier_wait");
b39b6e0c
AZ
77
78 pthread_cleanup_push (cl, NULL);
79
80 char mem[1];
81 struct iovec iov[1];
82 iov[0].iov_base = mem;
83 iov[0].iov_len = 1;
84
85 struct mmsghdr mm;
86 mm.msg_hdr.msg_name = &sun;
87 mm.msg_hdr.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
88 + strlen (sun.sun_path) + 1);
89 mm.msg_hdr.msg_iov = iov;
90 mm.msg_hdr.msg_iovlen = 1;
91 mm.msg_hdr.msg_control = NULL;
92 mm.msg_hdr.msg_controllen = 0;
93
94 ssize_t ret = sendmmsg (tempfd2, &mm, 1, 0);
95 if (ret == -1 && errno == ENOSYS)
96 exit (77);
97
98 pthread_cleanup_pop (0);
99
fa66f341 100 FAIL_EXIT1 ("sendmmsg returned");
b39b6e0c
AZ
101}
102
103struct cancel_tests tests[] =
104{
105 ADD_TEST (sendmmsg, 2, 1),
106};
107#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
108
109#include "tst-cancel4-common.c"