]>
Commit | Line | Data |
---|---|---|
b39b6e0c AZ |
1 | /* Check recvmmsg cancellation. |
2 | ||
bfff8b1b | 3 | Copyright (C) 2016-2017 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 | |
18 | <http://www.gnu.org/licenses/>. */ | |
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 | ||
35 | static void * | |
36 | tf_recvmmsg (void *arg) | |
37 | { | |
38 | struct sockaddr_un sun; | |
39 | ||
40 | tempfd = socket (AF_UNIX, SOCK_DGRAM, 0); | |
41 | if (tempfd == -1) | |
42 | { | |
43 | printf ("%s: first socket call failed\n", __FUNCTION__); | |
44 | exit (1); | |
45 | } | |
46 | ||
47 | int tries = 0; | |
48 | do | |
49 | { | |
50 | if (++tries > 10) | |
51 | { | |
52 | printf ("%s: too many unsuccessful bind calls\n", __FUNCTION__); | |
53 | } | |
54 | ||
55 | strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX"); | |
56 | if (mktemp (sun.sun_path) == NULL) | |
57 | { | |
58 | printf ("%s: cannot generate temp file name\n", __FUNCTION__); | |
59 | exit (1); | |
60 | } | |
61 | ||
62 | sun.sun_family = AF_UNIX; | |
63 | } | |
64 | while (bind (tempfd, (struct sockaddr *) &sun, | |
65 | offsetof (struct sockaddr_un, sun_path) | |
66 | + strlen (sun.sun_path) + 1) != 0); | |
67 | ||
68 | tempfname = strdup (sun.sun_path); | |
69 | ||
70 | tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0); | |
71 | if (tempfd2 == -1) | |
72 | { | |
73 | printf ("%s: second socket call failed\n", __FUNCTION__); | |
74 | exit (1); | |
75 | } | |
76 | ||
77 | int r = pthread_barrier_wait (&b2); | |
78 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) | |
79 | { | |
80 | printf ("%s: barrier_wait failed\n", __FUNCTION__); | |
81 | exit (1); | |
82 | } | |
83 | ||
84 | if (arg != NULL) | |
85 | { | |
86 | r = pthread_barrier_wait (&b2); | |
87 | if (r != 0 && r != PTHREAD_BARRIER_SERIAL_THREAD) | |
88 | { | |
89 | printf ("%s: 2nd barrier_wait failed\n", __FUNCTION__); | |
90 | exit (1); | |
91 | } | |
92 | } | |
93 | ||
94 | pthread_cleanup_push (cl, NULL); | |
95 | ||
96 | char mem[70]; | |
97 | struct iovec iov[1]; | |
98 | iov[0].iov_base = mem; | |
99 | iov[0].iov_len = arg == NULL ? sizeof (mem) : 0; | |
100 | ||
101 | struct mmsghdr mm; | |
102 | mm.msg_hdr.msg_name = &sun; | |
103 | mm.msg_hdr.msg_namelen = sizeof (sun); | |
104 | mm.msg_hdr.msg_iov = iov; | |
105 | mm.msg_hdr.msg_iovlen = 1; | |
106 | mm.msg_hdr.msg_control = NULL; | |
107 | mm.msg_hdr.msg_controllen = 0; | |
108 | ||
109 | ssize_t ret = recvmmsg (tempfd2, &mm, 1, 0, NULL); | |
110 | if (ret == -1 && errno == ENOSYS) | |
111 | exit (77); | |
112 | ||
113 | pthread_cleanup_pop (0); | |
114 | ||
115 | printf ("%s: recvmmsg returned\n", __FUNCTION__); | |
116 | ||
117 | exit (1); | |
118 | } | |
119 | ||
120 | struct cancel_tests tests[] = | |
121 | { | |
122 | ADD_TEST (recvmmsg, 2, 1), | |
123 | }; | |
124 | #define ntest_tf (sizeof (tests) / sizeof (tests[0])) | |
125 | ||
126 | #include "tst-cancel4-common.c" |