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