nptl: Add sendmmsg and recvmmsg cancellation tests
[glibc.git] / nptl / tst-cancel4_1.c
blob68296ec8ed22a5273a509663094c9a6833aa5c2b
1 /* Check sendmmsg cancellation.
3 Copyright (C) 2016 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
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.
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.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
25 #include <sys/un.h>
26 #include <sys/ipc.h>
27 #include <sys/msg.h>
28 #include <unistd.h>
29 #include <errno.h>
30 #include <pthread.h>
32 #include "tst-cancel4-common.h"
34 static void *
35 tf_sendmmsg (void *arg)
37 if (arg == NULL)
38 // XXX If somebody can provide a portable test case in which sendmmsg()
39 // blocks we can enable this test to run in both rounds.
40 abort ();
42 struct sockaddr_un sun;
44 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
45 if (tempfd == -1)
47 printf ("%s: first socket call failed\n", __FUNCTION__);
48 exit (1);
51 int tries = 0;
54 if (++tries > 10)
56 printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__);
59 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
60 if (mktemp (sun.sun_path) == NULL)
62 printf ("%s: cannot generate temp file name\n", __FUNCTION__);
63 exit (1);
66 sun.sun_family = AF_UNIX;
68 while (bind (tempfd, (struct sockaddr *) &sun,
69 offsetof (struct sockaddr_un, sun_path)
70 + strlen (sun.sun_path) + 1) != 0);
71 tempfname = strdup (sun.sun_path);
73 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
74 if (tempfd2 == -1)
76 printf ("%s: second socket call failed\n", __FUNCTION__);
77 exit (1);
80 int r = pthread_barrier_wait (&b2);
81 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
83 printf ("%s: barrier_wait failed\n", __FUNCTION__);
84 exit (1);
87 r = pthread_barrier_wait (&b2);
88 if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD)
90 printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__);
91 exit (1);
94 pthread_cleanup_push (cl, NULL);
96 char mem[1];
97 struct iovec iov[1];
98 iov[0].iov_base = mem;
99 iov[0].iov_len = 1;
101 struct mmsghdr mm;
102 mm.msg_hdr.msg_name = &sun;
103 mm.msg_hdr.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
104 + strlen (sun.sun_path) + 1);
105 mm.msg_hdr.msg_iov = iov;
106 mm.msg_hdr.msg_iovlen = 1;
107 mm.msg_hdr.msg_control = NULL;
108 mm.msg_hdr.msg_controllen = 0;
110 ssize_t ret = sendmmsg (tempfd2, &mm, 1, 0);
111 if (ret == -1 && errno == ENOSYS)
112 exit (77);
114 pthread_cleanup_pop (0);
116 printf ("%s: sendmmsg returned\n", __FUNCTION__);
118 exit (1);
121 struct cancel_tests tests[] =
123 ADD_TEST (sendmmsg, 2, 1),
125 #define ntest_tf (sizeof (tests) / sizeof (tests[0]))
127 #include "tst-cancel4-common.c"