]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-cancel4.c
Add per-thread cache to malloc
[thirdparty/glibc.git] / nptl / tst-cancel4.c
CommitLineData
bfff8b1b 1/* Copyright (C) 2002-2017 Free Software Foundation, Inc.
76a50749
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
76a50749
UD
18
19/* NOTE: this tests functionality beyond POSIX. POSIX does not allow
20 exit to be called more than once. */
21
ceaa9889 22#include <stddef.h>
76a50749
UD
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
b39b6e0c
AZ
26#include <sys/types.h>
27#include <sys/socket.h>
28#include <sys/un.h>
29#include <sys/ipc.h>
30#include <sys/msg.h>
76a50749 31#include <unistd.h>
b39b6e0c 32#include <errno.h>
ceaa9889 33#include <limits.h>
b39b6e0c
AZ
34#include <pthread.h>
35#include <fcntl.h>
36#include <termios.h>
047aec8f 37#include <sys/mman.h>
76a50749 38#include <sys/poll.h>
76a50749 39#include <sys/wait.h>
ceaa9889 40#include <sys/stat.h>
9fe3c80c 41#include <sys/uio.h>
76a50749 42
26676450 43
f23b30e2
UD
44/* Since STREAMS are not supported in the standard Linux kernel and
45 there we don't advertise STREAMS as supported is no need to test
46 the STREAMS related functions. This affects
26676450
UD
47 getmsg() getpmsg() putmsg()
48 putpmsg()
49
50 lockf() and fcntl() are tested in tst-cancel16.
51
52 pthread_join() is tested in tst-join5.
53
54 pthread_testcancel()'s only purpose is to allow cancellation. This
55 is tested in several places.
56
57 sem_wait() and sem_timedwait() are checked in tst-cancel1[2345] tests.
58
1683daeb
UD
59 mq_send(), mq_timedsend(), mq_receive() and mq_timedreceive() are checked
60 in tst-mqueue8{,x} tests.
f23b30e2
UD
61
62 aio_suspend() is tested in tst-cancel17.
63
64 clock_nanosleep() is tested in tst-cancel18.
76a50749 65
b39b6e0c
AZ
66 Linux sendmmsg and recvmmsg are checked in tst-cancel4_1.c and
67 tst-cancel4_2.c respectively.
68*/
76a50749 69
b39b6e0c 70#include "tst-cancel4-common.h"
76a50749 71
2918b0d0 72
483e95d0
UD
73#ifndef IPC_ADDVAL
74# define IPC_ADDVAL 0
75#endif
76
483e95d0 77
76a50749
UD
78static void *
79tf_read (void *arg)
80{
26676450 81 int fd;
26676450
UD
82
83 if (arg == NULL)
84 fd = fds[0];
85 else
86 {
87 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
88 tempfd = fd = mkstemp (fname);
89 if (fd == -1)
fa66f341 90 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
91 unlink (fname);
92
fa66f341 93 xpthread_barrier_wait (&b2);
26676450
UD
94 }
95
fa66f341 96 xpthread_barrier_wait (&b2);
76a50749 97
f23b30e2 98 ssize_t s;
0e0deb03
UD
99 pthread_cleanup_push (cl, NULL);
100
76a50749 101 char buf[100];
f23b30e2 102 s = read (fd, buf, sizeof (buf));
76a50749 103
0e0deb03
UD
104 pthread_cleanup_pop (0);
105
fa66f341 106 FAIL_EXIT1 ("read returns with %zd", s);
76a50749
UD
107}
108
109
110static void *
111tf_readv (void *arg)
112{
26676450 113 int fd;
26676450
UD
114
115 if (arg == NULL)
116 fd = fds[0];
117 else
118 {
119 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
120 tempfd = fd = mkstemp (fname);
121 if (fd == -1)
fa66f341 122 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
123 unlink (fname);
124
fa66f341 125 xpthread_barrier_wait (&b2);
26676450
UD
126 }
127
fa66f341 128 xpthread_barrier_wait (&b2);
76a50749 129
f23b30e2 130 ssize_t s;
0e0deb03
UD
131 pthread_cleanup_push (cl, NULL);
132
76a50749
UD
133 char buf[100];
134 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
f23b30e2 135 s = readv (fd, iov, 1);
76a50749 136
0e0deb03
UD
137 pthread_cleanup_pop (0);
138
fa66f341 139 FAIL_EXIT1 ("readv returns with %zd", s);
76a50749
UD
140}
141
142
143static void *
144tf_write (void *arg)
145{
26676450 146 int fd;
26676450
UD
147
148 if (arg == NULL)
149 fd = fds[1];
150 else
151 {
152 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
153 tempfd = fd = mkstemp (fname);
154 if (fd == -1)
fa66f341 155 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
156 unlink (fname);
157
fa66f341 158 xpthread_barrier_wait (&b2);
26676450
UD
159 }
160
fa66f341 161 xpthread_barrier_wait (&b2);
76a50749 162
f23b30e2 163 ssize_t s;
0e0deb03
UD
164 pthread_cleanup_push (cl, NULL);
165
8074c5c5 166 char buf[WRITE_BUFFER_SIZE];
76a50749 167 memset (buf, '\0', sizeof (buf));
f23b30e2 168 s = write (fd, buf, sizeof (buf));
76a50749 169
0e0deb03
UD
170 pthread_cleanup_pop (0);
171
fa66f341 172 FAIL_EXIT1 ("write returns with %zd", s);
76a50749
UD
173}
174
175
176static void *
177tf_writev (void *arg)
178{
26676450 179 int fd;
26676450
UD
180
181 if (arg == NULL)
182 fd = fds[1];
183 else
184 {
185 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
186 tempfd = fd = mkstemp (fname);
187 if (fd == -1)
fa66f341 188 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
189 unlink (fname);
190
fa66f341 191 xpthread_barrier_wait (&b2);
26676450
UD
192 }
193
fa66f341 194 xpthread_barrier_wait (&b2);
76a50749 195
f23b30e2 196 ssize_t s;
0e0deb03
UD
197 pthread_cleanup_push (cl, NULL);
198
8074c5c5 199 char buf[WRITE_BUFFER_SIZE];
76a50749
UD
200 memset (buf, '\0', sizeof (buf));
201 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
f23b30e2 202 s = writev (fd, iov, 1);
76a50749 203
0e0deb03
UD
204 pthread_cleanup_pop (0);
205
fa66f341 206 FAIL_EXIT1 ("writev returns with %zd", s);
76a50749
UD
207}
208
209
210static void *
211tf_sleep (void *arg)
212{
fa66f341 213 xpthread_barrier_wait (&b2);
76a50749 214
26676450 215 if (arg != NULL)
fa66f341 216 xpthread_barrier_wait (&b2);
26676450 217
0e0deb03
UD
218 pthread_cleanup_push (cl, NULL);
219
26676450 220 sleep (arg == NULL ? 1000000 : 0);
76a50749 221
0e0deb03
UD
222 pthread_cleanup_pop (0);
223
fa66f341 224 FAIL_EXIT1 ("sleep returns");
76a50749
UD
225}
226
227
228static void *
229tf_usleep (void *arg)
230{
fa66f341 231 xpthread_barrier_wait (&b2);
76a50749 232
26676450 233 if (arg != NULL)
fa66f341 234 xpthread_barrier_wait (&b2);
26676450 235
0e0deb03
UD
236 pthread_cleanup_push (cl, NULL);
237
26676450 238 usleep (arg == NULL ? (useconds_t) ULONG_MAX : 0);
76a50749 239
0e0deb03
UD
240 pthread_cleanup_pop (0);
241
fa66f341 242 FAIL_EXIT1 ("usleep returns");
76a50749
UD
243}
244
245
246static void *
247tf_nanosleep (void *arg)
248{
fa66f341 249 xpthread_barrier_wait (&b2);
76a50749 250
26676450 251 if (arg != NULL)
fa66f341 252 xpthread_barrier_wait (&b2);
26676450 253
0e0deb03
UD
254 pthread_cleanup_push (cl, NULL);
255
26676450 256 struct timespec ts = { .tv_sec = arg == NULL ? 10000000 : 0, .tv_nsec = 0 };
f23b30e2 257 TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));
76a50749 258
0e0deb03
UD
259 pthread_cleanup_pop (0);
260
fa66f341 261 FAIL_EXIT1 ("nanosleep returns");
76a50749
UD
262}
263
264
265static void *
266tf_select (void *arg)
267{
26676450 268 int fd;
26676450
UD
269
270 if (arg == NULL)
271 fd = fds[0];
272 else
273 {
274 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
275 tempfd = fd = mkstemp (fname);
276 if (fd == -1)
fa66f341 277 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
278 unlink (fname);
279
fa66f341 280 xpthread_barrier_wait (&b2);
26676450
UD
281 }
282
fa66f341 283 xpthread_barrier_wait (&b2);
76a50749
UD
284
285 fd_set rfs;
286 FD_ZERO (&rfs);
26676450 287 FD_SET (fd, &rfs);
76a50749 288
f23b30e2 289 int s;
0e0deb03
UD
290 pthread_cleanup_push (cl, NULL);
291
f23b30e2
UD
292 s = select (fd + 1, &rfs, NULL, NULL, NULL);
293
294 pthread_cleanup_pop (0);
76a50749 295
fa66f341 296 FAIL_EXIT1 ("select returns with %d: %m", s);
76a50749
UD
297}
298
299
300static void *
301tf_pselect (void *arg)
302{
26676450 303 int fd;
26676450
UD
304
305 if (arg == NULL)
306 fd = fds[0];
307 else
308 {
309 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
310 tempfd = fd = mkstemp (fname);
311 if (fd == -1)
fa66f341 312 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
313 unlink (fname);
314
fa66f341 315 xpthread_barrier_wait (&b2);
26676450
UD
316 }
317
fa66f341 318 xpthread_barrier_wait (&b2);
76a50749
UD
319
320 fd_set rfs;
321 FD_ZERO (&rfs);
26676450 322 FD_SET (fd, &rfs);
76a50749 323
f23b30e2 324 int s;
0e0deb03
UD
325 pthread_cleanup_push (cl, NULL);
326
f23b30e2
UD
327 s = pselect (fd + 1, &rfs, NULL, NULL, NULL, NULL);
328
329 pthread_cleanup_pop (0);
76a50749 330
fa66f341 331 FAIL_EXIT1 ("pselect returns with %d: %m", s);
76a50749
UD
332}
333
334
335static void *
336tf_poll (void *arg)
337{
26676450 338 int fd;
26676450
UD
339
340 if (arg == NULL)
341 fd = fds[0];
342 else
343 {
344 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
345 tempfd = fd = mkstemp (fname);
346 if (fd == -1)
fa66f341 347 FAIL_EXIT1 ("mkstemp failed: %m");
26676450
UD
348 unlink (fname);
349
fa66f341 350 xpthread_barrier_wait (&b2);
26676450
UD
351 }
352
fa66f341 353 xpthread_barrier_wait (&b2);
76a50749 354
26676450 355 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
76a50749 356
f23b30e2 357 int s;
0e0deb03
UD
358 pthread_cleanup_push (cl, NULL);
359
f23b30e2
UD
360 s = poll (rfs, 1, -1);
361
362 pthread_cleanup_pop (0);
76a50749 363
fa66f341 364 FAIL_EXIT1 ("poll returns with %d: %m", s);
76a50749
UD
365}
366
367
7c65e900
UD
368static void *
369tf_ppoll (void *arg)
370{
371 int fd;
7c65e900
UD
372
373 if (arg == NULL)
374 fd = fds[0];
375 else
376 {
377 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
378 tempfd = fd = mkstemp (fname);
379 if (fd == -1)
fa66f341 380 FAIL_EXIT1 ("mkstemp failed: %m");
7c65e900
UD
381 unlink (fname);
382
fa66f341 383 xpthread_barrier_wait (&b2);
7c65e900
UD
384 }
385
fa66f341 386 xpthread_barrier_wait (&b2);
7c65e900
UD
387
388 struct pollfd rfs[1] = { [0] = { .fd = fd, .events = POLLIN } };
389
390 int s;
391 pthread_cleanup_push (cl, NULL);
392
393 s = ppoll (rfs, 1, NULL, NULL);
394
395 pthread_cleanup_pop (0);
396
fa66f341 397 FAIL_EXIT1 ("ppoll returns with %d: %m", s);
7c65e900
UD
398}
399
400
76a50749
UD
401static void *
402tf_wait (void *arg)
403{
76a50749
UD
404 pid_t pid = fork ();
405 if (pid == -1)
fa66f341 406 FAIL_EXIT1 ("fork: %m");
76a50749
UD
407
408 if (pid == 0)
409 {
410 /* Make the program disappear after a while. */
26676450
UD
411 if (arg == NULL)
412 sleep (10);
76a50749
UD
413 exit (0);
414 }
415
26676450
UD
416 if (arg != NULL)
417 {
418 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
419 while (nanosleep (&ts, &ts) != 0)
420 continue;
421
fa66f341 422 xpthread_barrier_wait (&b2);
26676450
UD
423 }
424
fa66f341 425 xpthread_barrier_wait (&b2);
26676450 426
f23b30e2 427 int s;
0e0deb03
UD
428 pthread_cleanup_push (cl, NULL);
429
f23b30e2
UD
430 s = wait (NULL);
431
432 pthread_cleanup_pop (0);
76a50749 433
fa66f341 434 FAIL_EXIT1 ("wait returns with %d: %m", s);
76a50749
UD
435}
436
437
438static void *
439tf_waitpid (void *arg)
440{
76a50749
UD
441 pid_t pid = fork ();
442 if (pid == -1)
fa66f341 443 FAIL_EXIT1 ("fork: %m");
76a50749
UD
444
445 if (pid == 0)
446 {
447 /* Make the program disappear after a while. */
26676450
UD
448 if (arg == NULL)
449 sleep (10);
76a50749
UD
450 exit (0);
451 }
452
26676450
UD
453 if (arg != NULL)
454 {
455 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
456 while (nanosleep (&ts, &ts) != 0)
457 continue;
458
fa66f341 459 xpthread_barrier_wait (&b2);
26676450
UD
460 }
461
fa66f341 462 xpthread_barrier_wait (&b2);
26676450 463
f23b30e2 464 int s;
fa66f341 465 pthread_cleanup_push (cl, NULL);
0e0deb03 466
f23b30e2
UD
467 s = waitpid (-1, NULL, 0);
468
469 pthread_cleanup_pop (0);
76a50749 470
fa66f341 471 FAIL_EXIT1 ("waitpid returns with %d: %m", s);
76a50749
UD
472}
473
474
475static void *
476tf_waitid (void *arg)
477{
76a50749
UD
478 pid_t pid = fork ();
479 if (pid == -1)
fa66f341 480 FAIL_EXIT1 ("fork: %m");
76a50749
UD
481
482 if (pid == 0)
483 {
484 /* Make the program disappear after a while. */
26676450
UD
485 if (arg == NULL)
486 sleep (10);
76a50749
UD
487 exit (0);
488 }
489
26676450
UD
490 if (arg != NULL)
491 {
492 struct timespec ts = { .tv_sec = 0, .tv_nsec = 100000000 };
493 while (nanosleep (&ts, &ts) != 0)
494 continue;
495
fa66f341 496 xpthread_barrier_wait (&b2);
26676450
UD
497 }
498
fa66f341 499 xpthread_barrier_wait (&b2);
26676450 500
f23b30e2 501 int s;
0e0deb03
UD
502 pthread_cleanup_push (cl, NULL);
503
4fb907b7
RM
504#ifndef WEXITED
505# define WEXITED 0
506#endif
76a50749 507 siginfo_t si;
4fb907b7 508 s = waitid (P_PID, pid, &si, WEXITED);
f23b30e2
UD
509
510 pthread_cleanup_pop (0);
76a50749 511
fa66f341 512 FAIL_EXIT1 ("waitid returns with %d: %m", s);
76a50749
UD
513}
514
515
26676450
UD
516static void *
517tf_sigpause (void *arg)
76a50749 518{
fa66f341 519 xpthread_barrier_wait (&b2);
76a50749 520
26676450 521 if (arg != NULL)
fa66f341 522 xpthread_barrier_wait (&b2);
76a50749 523
26676450 524 pthread_cleanup_push (cl, NULL);
0e0deb03 525
2918b0d0 526 sigpause (sigmask (SIGINT));
76a50749 527
26676450
UD
528 pthread_cleanup_pop (0);
529
fa66f341 530 FAIL_EXIT1 ("sigpause returned");
26676450
UD
531}
532
533
534static void *
535tf_sigsuspend (void *arg)
536{
fa66f341 537 xpthread_barrier_wait (&b2);
26676450
UD
538
539 if (arg != NULL)
fa66f341 540 xpthread_barrier_wait (&b2);
76a50749 541
26676450 542 pthread_cleanup_push (cl, NULL);
76a50749 543
26676450
UD
544 /* Just for fun block all signals. */
545 sigset_t mask;
546 sigfillset (&mask);
547 sigsuspend (&mask);
76a50749 548
26676450
UD
549 pthread_cleanup_pop (0);
550
fa66f341 551 FAIL_EXIT1 ("sigsuspend returned");
26676450
UD
552}
553
554
555static void *
556tf_sigwait (void *arg)
557{
fa66f341 558 xpthread_barrier_wait (&b2);
26676450
UD
559
560 if (arg != NULL)
fa66f341 561 xpthread_barrier_wait (&b2);
26676450 562
26676450
UD
563 /* Block SIGUSR1. */
564 sigset_t mask;
97b6614c 565 sigemptyset (&mask);
26676450 566 sigaddset (&mask, SIGUSR1);
fa66f341 567 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK, &mask, NULL) == 0);
26676450 568
26676450 569 int sig;
f23b30e2 570 pthread_cleanup_push (cl, NULL);
26676450 571
f23b30e2
UD
572 /* Wait for SIGUSR1. */
573 sigwait (&mask, &sig);
26676450
UD
574
575 pthread_cleanup_pop (0);
576
fa66f341 577 FAIL_EXIT1 ("sigwait returned with signal %d", sig);
26676450
UD
578}
579
580
581static void *
582tf_sigwaitinfo (void *arg)
583{
fa66f341 584 xpthread_barrier_wait (&b2);
26676450
UD
585
586 if (arg != NULL)
fa66f341 587 xpthread_barrier_wait (&b2);
26676450 588
26676450
UD
589 /* Block SIGUSR1. */
590 sigset_t mask;
97b6614c 591 sigemptyset (&mask);
26676450 592 sigaddset (&mask, SIGUSR1);
fa66f341 593 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK, &mask, NULL) == 0);
26676450 594
26676450 595 siginfo_t info;
f23b30e2
UD
596 pthread_cleanup_push (cl, NULL);
597
598 /* Wait for SIGUSR1. */
26676450
UD
599 sigwaitinfo (&mask, &info);
600
f23b30e2
UD
601 pthread_cleanup_pop (0);
602
fa66f341 603 FAIL_EXIT1 ("sigwaitinfo returned with signal %d", info.si_signo);
26676450
UD
604}
605
606
607static void *
608tf_sigtimedwait (void *arg)
609{
fa66f341 610 xpthread_barrier_wait (&b2);
26676450
UD
611
612 if (arg != NULL)
fa66f341 613 xpthread_barrier_wait (&b2);
26676450 614
26676450
UD
615 /* Block SIGUSR1. */
616 sigset_t mask;
97b6614c 617 sigemptyset (&mask);
26676450 618 sigaddset (&mask, SIGUSR1);
fa66f341 619 TEST_VERIFY_EXIT (pthread_sigmask (SIG_BLOCK, &mask, NULL) == 0);
26676450
UD
620
621 /* Wait for SIGUSR1. */
622 siginfo_t info;
623 struct timespec ts = { .tv_sec = 60, .tv_nsec = 0 };
f23b30e2
UD
624 pthread_cleanup_push (cl, NULL);
625
26676450
UD
626 sigtimedwait (&mask, &info, &ts);
627
f23b30e2
UD
628 pthread_cleanup_pop (0);
629
fa66f341 630 FAIL_EXIT1 ("sigtimedwait returned with signal %d", info.si_signo);
26676450
UD
631}
632
633
634static void *
635tf_pause (void *arg)
636{
fa66f341 637 xpthread_barrier_wait (&b2);
26676450
UD
638
639 if (arg != NULL)
fa66f341 640 xpthread_barrier_wait (&b2);
26676450
UD
641
642 pthread_cleanup_push (cl, NULL);
643
644 pause ();
645
646 pthread_cleanup_pop (0);
647
fa66f341 648 FAIL_EXIT1 ("pause returned");
26676450
UD
649}
650
651
652static void *
653tf_accept (void *arg)
654{
655 struct sockaddr_un sun;
656 /* To test a non-blocking accept call we make the call file by using
657 a datagrame socket. */
658 int pf = arg == NULL ? SOCK_STREAM : SOCK_DGRAM;
659
660 tempfd = socket (AF_UNIX, pf, 0);
661 if (tempfd == -1)
fa66f341
AZ
662 FAIL_EXIT1 ("socket (AF_UNIX, %s, 0): %m", arg == NULL ? "SOCK_STREAM"
663 : "SOCK_DGRAM");
26676450
UD
664
665 int tries = 0;
666 do
667 {
fa66f341 668 TEST_VERIFY_EXIT (tries++ < 10);
26676450 669
f23b30e2 670 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-1-XXXXXX");
fa66f341 671 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
26676450
UD
672
673 sun.sun_family = AF_UNIX;
674 }
675 while (bind (tempfd, (struct sockaddr *) &sun,
676 offsetof (struct sockaddr_un, sun_path)
677 + strlen (sun.sun_path) + 1) != 0);
678
679 unlink (sun.sun_path);
680
681 listen (tempfd, 5);
682
683 socklen_t len = sizeof (sun);
684
fa66f341 685 xpthread_barrier_wait (&b2);
26676450
UD
686
687 if (arg != NULL)
fa66f341 688 xpthread_barrier_wait (&b2);
26676450
UD
689
690 pthread_cleanup_push (cl, NULL);
691
692 accept (tempfd, (struct sockaddr *) &sun, &len);
693
694 pthread_cleanup_pop (0);
695
fa66f341 696 FAIL_EXIT1 ("accept returned");
26676450
UD
697}
698
699
700static void *
701tf_send (void *arg)
702{
703 struct sockaddr_un sun;
704
705 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
706 if (tempfd == -1)
fa66f341 707 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
26676450
UD
708
709 int tries = 0;
710 do
711 {
fa66f341 712 TEST_VERIFY_EXIT (tries++ < 10);
26676450 713
f23b30e2 714 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
fa66f341 715 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
26676450
UD
716
717 sun.sun_family = AF_UNIX;
718 }
719 while (bind (tempfd, (struct sockaddr *) &sun,
720 offsetof (struct sockaddr_un, sun_path)
721 + strlen (sun.sun_path) + 1) != 0);
722
723 listen (tempfd, 5);
724
725 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
726 if (tempfd2 == -1)
fa66f341 727 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
26676450
UD
728
729 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
fa66f341 730 FAIL_EXIT1 ("connect: %m");
26676450
UD
731
732 unlink (sun.sun_path);
733
fa66f341 734 xpthread_barrier_wait (&b2);
26676450
UD
735
736 if (arg != NULL)
fa66f341 737 xpthread_barrier_wait (&b2);
26676450
UD
738
739 pthread_cleanup_push (cl, NULL);
740
741 /* Very large block, so that the send call blocks. */
742 char mem[700000];
743
744 send (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0);
745
746 pthread_cleanup_pop (0);
747
fa66f341 748 FAIL_EXIT1 ("send returned");
26676450
UD
749}
750
751
752static void *
753tf_recv (void *arg)
754{
755 struct sockaddr_un sun;
756
757 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
758 if (tempfd == -1)
fa66f341 759 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
26676450
UD
760
761 int tries = 0;
762 do
763 {
fa66f341 764 TEST_VERIFY_EXIT (tries++ < 10);
26676450 765
f23b30e2 766 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-3-XXXXXX");
fa66f341 767 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
26676450
UD
768
769 sun.sun_family = AF_UNIX;
770 }
771 while (bind (tempfd, (struct sockaddr *) &sun,
772 offsetof (struct sockaddr_un, sun_path)
773 + strlen (sun.sun_path) + 1) != 0);
774
775 listen (tempfd, 5);
776
777 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
778 if (tempfd2 == -1)
fa66f341 779 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
26676450
UD
780
781 if (connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun)) != 0)
fa66f341 782 FAIL_EXIT1 ("connect: %m");
26676450
UD
783
784 unlink (sun.sun_path);
785
fa66f341 786 xpthread_barrier_wait (&b2);
26676450
UD
787
788 if (arg != NULL)
fa66f341 789 xpthread_barrier_wait (&b2);
26676450
UD
790
791 pthread_cleanup_push (cl, NULL);
792
793 char mem[70];
794
795 recv (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0);
796
797 pthread_cleanup_pop (0);
798
fa66f341 799 FAIL_EXIT1 ("recv returned");
26676450
UD
800}
801
802
803static void *
804tf_recvfrom (void *arg)
805{
806 struct sockaddr_un sun;
807
808 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
809 if (tempfd == -1)
fa66f341 810 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
26676450
UD
811
812 int tries = 0;
813 do
814 {
fa66f341 815 TEST_VERIFY_EXIT (tries++ < 10);
26676450 816
f23b30e2 817 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-4-XXXXXX");
fa66f341 818 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
26676450
UD
819
820 sun.sun_family = AF_UNIX;
821 }
822 while (bind (tempfd, (struct sockaddr *) &sun,
823 offsetof (struct sockaddr_un, sun_path)
824 + strlen (sun.sun_path) + 1) != 0);
825
826 tempfname = strdup (sun.sun_path);
827
828 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
829 if (tempfd2 == -1)
fa66f341 830 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
26676450 831
fa66f341 832 xpthread_barrier_wait (&b2);
26676450
UD
833
834 if (arg != NULL)
fa66f341 835 xpthread_barrier_wait (&b2);
26676450
UD
836
837 pthread_cleanup_push (cl, NULL);
838
839 char mem[70];
840 socklen_t len = sizeof (sun);
841
842 recvfrom (tempfd2, mem, arg == NULL ? sizeof (mem) : 0, 0,
843 (struct sockaddr *) &sun, &len);
844
845 pthread_cleanup_pop (0);
846
fa66f341 847 FAIL_EXIT1 ("recvfrom returned");
26676450
UD
848}
849
850
851static void *
852tf_recvmsg (void *arg)
853{
854 struct sockaddr_un sun;
855
856 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
857 if (tempfd == -1)
fa66f341 858 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
26676450
UD
859
860 int tries = 0;
861 do
862 {
fa66f341 863 TEST_VERIFY_EXIT (tries++ < 10);
26676450 864
f23b30e2 865 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-5-XXXXXX");
fa66f341 866 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
26676450
UD
867
868 sun.sun_family = AF_UNIX;
869 }
870 while (bind (tempfd, (struct sockaddr *) &sun,
871 offsetof (struct sockaddr_un, sun_path)
872 + strlen (sun.sun_path) + 1) != 0);
873
874 tempfname = strdup (sun.sun_path);
875
876 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
877 if (tempfd2 == -1)
fa66f341 878 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
26676450 879
fa66f341 880 xpthread_barrier_wait (&b2);
26676450
UD
881
882 if (arg != NULL)
fa66f341 883 xpthread_barrier_wait (&b2);
26676450
UD
884
885 pthread_cleanup_push (cl, NULL);
886
887 char mem[70];
888 struct iovec iov[1];
889 iov[0].iov_base = mem;
890 iov[0].iov_len = arg == NULL ? sizeof (mem) : 0;
891
892 struct msghdr m;
893 m.msg_name = &sun;
894 m.msg_namelen = sizeof (sun);
895 m.msg_iov = iov;
896 m.msg_iovlen = 1;
897 m.msg_control = NULL;
898 m.msg_controllen = 0;
899
900 recvmsg (tempfd2, &m, 0);
901
902 pthread_cleanup_pop (0);
903
fa66f341 904 FAIL_EXIT1 ("recvmsg returned");
26676450
UD
905}
906
047aec8f
UD
907static void *
908tf_open (void *arg)
909{
910 if (arg == NULL)
047aec8f 911 {
2918b0d0
AZ
912 fifofd = mkfifo (fifoname, S_IWUSR | S_IRUSR);
913 if (fifofd == -1)
fa66f341 914 FAIL_EXIT1 ("mkfifo: %m");
2918b0d0
AZ
915 }
916 else
917 {
fa66f341 918 xpthread_barrier_wait (&b2);
047aec8f
UD
919 }
920
fa66f341 921 xpthread_barrier_wait (&b2);
047aec8f 922
2918b0d0 923 pthread_cleanup_push (cl_fifo, NULL);
047aec8f 924
2918b0d0 925 open (arg ? "Makefile" : fifoname, O_RDONLY);
047aec8f
UD
926
927 pthread_cleanup_pop (0);
928
fa66f341 929 FAIL_EXIT1 ("open returned");
047aec8f
UD
930}
931
932
933static void *
934tf_close (void *arg)
935{
936 if (arg == NULL)
937 // XXX If somebody can provide a portable test case in which close()
938 // blocks we can enable this test to run in both rounds.
939 abort ();
940
941 char fname[] = "/tmp/tst-cancel-fd-XXXXXX";
942 tempfd = mkstemp (fname);
943 if (tempfd == -1)
fa66f341 944 FAIL_EXIT1 ("mkstemp failed: %m");
047aec8f
UD
945 unlink (fname);
946
fa66f341 947 xpthread_barrier_wait (&b2);
047aec8f 948
fa66f341 949 xpthread_barrier_wait (&b2);
047aec8f
UD
950
951 pthread_cleanup_push (cl, NULL);
952
953 close (tempfd);
954
955 pthread_cleanup_pop (0);
956
fa66f341 957 FAIL_EXIT1 ("close returned");
047aec8f
UD
958}
959
960
961static void *
962tf_pread (void *arg)
963{
964 if (arg == NULL)
965 // XXX If somebody can provide a portable test case in which pread()
966 // blocks we can enable this test to run in both rounds.
967 abort ();
968
969 tempfd = open ("Makefile", O_RDONLY);
970 if (tempfd == -1)
fa66f341 971 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
047aec8f 972
fa66f341 973 xpthread_barrier_wait (&b2);
047aec8f 974
fa66f341 975 xpthread_barrier_wait (&b2);
047aec8f
UD
976
977 pthread_cleanup_push (cl, NULL);
978
979 char mem[10];
980 pread (tempfd, mem, sizeof (mem), 0);
981
982 pthread_cleanup_pop (0);
983
fa66f341 984 FAIL_EXIT1 ("pread returned");
047aec8f
UD
985}
986
987
988static void *
989tf_pwrite (void *arg)
990{
991 if (arg == NULL)
992 // XXX If somebody can provide a portable test case in which pwrite()
993 // blocks we can enable this test to run in both rounds.
994 abort ();
995
996 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
997 tempfd = mkstemp (fname);
998 if (tempfd == -1)
fa66f341 999 FAIL_EXIT1 ("mkstemp failed: %m");
047aec8f
UD
1000 unlink (fname);
1001
fa66f341 1002 xpthread_barrier_wait (&b2);
047aec8f 1003
fa66f341 1004 xpthread_barrier_wait (&b2);
047aec8f
UD
1005
1006 pthread_cleanup_push (cl, NULL);
1007
1008 char mem[10];
1009 pwrite (tempfd, mem, sizeof (mem), 0);
1010
1011 pthread_cleanup_pop (0);
1012
fa66f341 1013 FAIL_EXIT1 ("pwrite returned");
047aec8f
UD
1014}
1015
4e778151
AZ
1016static void *
1017tf_preadv (void *arg)
1018{
1019 int fd;
4e778151
AZ
1020
1021 if (arg == NULL)
1022 /* XXX If somebody can provide a portable test case in which preadv
1023 blocks we can enable this test to run in both rounds. */
1024 abort ();
1025
1026 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1027 tempfd = fd = mkstemp (fname);
1028 if (fd == -1)
fa66f341 1029 FAIL_EXIT1 ("mkstemp failed: %m");
4e778151
AZ
1030 unlink (fname);
1031
fa66f341 1032 xpthread_barrier_wait (&b2);
4e778151 1033
fa66f341 1034 xpthread_barrier_wait (&b2);
4e778151
AZ
1035
1036 ssize_t s;
1037 pthread_cleanup_push (cl, NULL);
1038
1039 char buf[100];
1040 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1041 s = preadv (fd, iov, 1, 0);
1042
1043 pthread_cleanup_pop (0);
1044
fa66f341 1045 FAIL_EXIT1 ("preadv returns with %zd", s);
4e778151 1046}
047aec8f 1047
af5fdf5a
AZ
1048static void *
1049tf_pwritev (void *arg)
1050{
1051 int fd;
af5fdf5a
AZ
1052
1053 if (arg == NULL)
1054 /* XXX If somebody can provide a portable test case in which pwritev
1055 blocks we can enable this test to run in both rounds. */
1056 abort ();
1057
1058 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1059 tempfd = fd = mkstemp (fname);
1060 if (fd == -1)
fa66f341 1061 FAIL_EXIT1 ("mkstemp failed: %m");
af5fdf5a
AZ
1062 unlink (fname);
1063
fa66f341 1064 xpthread_barrier_wait (&b2);
af5fdf5a 1065
fa66f341 1066 xpthread_barrier_wait (&b2);
af5fdf5a
AZ
1067
1068 ssize_t s;
1069 pthread_cleanup_push (cl, NULL);
1070
1071 char buf[WRITE_BUFFER_SIZE];
1072 memset (buf, '\0', sizeof (buf));
1073 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1074 s = pwritev (fd, iov, 1, 0);
1075
1076 pthread_cleanup_pop (0);
1077
fa66f341 1078 FAIL_EXIT1 ("pwritev returns with %zd", s);
af5fdf5a
AZ
1079}
1080
52bd9381
AZ
1081static void *
1082tf_pwritev2 (void *arg)
1083{
1084 int fd;
1085
1086 if (arg == NULL)
1087 /* XXX If somebody can provide a portable test case in which pwritev2
1088 blocks we can enable this test to run in both rounds. */
1089 abort ();
1090
1091 errno = 0;
1092
1093 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1094 tempfd = fd = mkstemp (fname);
1095 if (fd == -1)
1096 FAIL_EXIT1 ("mkstemp: %m");
1097 unlink (fname);
1098
1099 xpthread_barrier_wait (&b2);
1100
1101 xpthread_barrier_wait (&b2);
1102
1103 ssize_t s;
1104 pthread_cleanup_push (cl, NULL);
1105
1106 char buf[WRITE_BUFFER_SIZE];
1107 memset (buf, '\0', sizeof (buf));
1108 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1109 s = pwritev2 (fd, iov, 1, 0, 0);
1110
1111 pthread_cleanup_pop (0);
1112
1113 FAIL_EXIT1 ("pwritev2 returns with %zd", s);
1114}
1115
1116static void *
1117tf_preadv2 (void *arg)
1118{
1119 int fd;
1120
1121 if (arg == NULL)
1122 /* XXX If somebody can provide a portable test case in which preadv2
1123 blocks we can enable this test to run in both rounds. */
1124 abort ();
1125
1126 errno = 0;
1127
1128 char fname[] = "/tmp/tst-cancel4-fd-XXXXXX";
1129 tempfd = fd = mkstemp (fname);
1130 if (fd == -1)
1131 FAIL_EXIT1 ("mkstemp failed: %m");
1132 unlink (fname);
1133
1134 xpthread_barrier_wait (&b2);
1135
1136 xpthread_barrier_wait (&b2);
1137
1138 ssize_t s;
1139 pthread_cleanup_push (cl, NULL);
1140
1141 char buf[100];
1142 struct iovec iov[1] = { [0] = { .iov_base = buf, .iov_len = sizeof (buf) } };
1143 s = preadv2 (fd, iov, 1, 0, 0);
1144
1145 pthread_cleanup_pop (0);
1146
1147 FAIL_EXIT1 ("preadv2 returns with %zd", s);
1148}
1149
047aec8f
UD
1150static void *
1151tf_fsync (void *arg)
1152{
1153 if (arg == NULL)
1154 // XXX If somebody can provide a portable test case in which fsync()
1155 // blocks we can enable this test to run in both rounds.
1156 abort ();
1157
1158 tempfd = open ("Makefile", O_RDONLY);
1159 if (tempfd == -1)
fa66f341 1160 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
047aec8f 1161
fa66f341 1162 xpthread_barrier_wait (&b2);
047aec8f 1163
fa66f341 1164 xpthread_barrier_wait (&b2);
047aec8f
UD
1165
1166 pthread_cleanup_push (cl, NULL);
1167
1168 fsync (tempfd);
1169
1170 pthread_cleanup_pop (0);
1171
fa66f341 1172 FAIL_EXIT1 ("fsync returned");
047aec8f
UD
1173}
1174
1175
aa75f64c
UD
1176static void *
1177tf_fdatasync (void *arg)
1178{
1179 if (arg == NULL)
1180 // XXX If somebody can provide a portable test case in which fdatasync()
1181 // blocks we can enable this test to run in both rounds.
1182 abort ();
1183
1184 tempfd = open ("Makefile", O_RDONLY);
1185 if (tempfd == -1)
fa66f341 1186 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
aa75f64c 1187
fa66f341 1188 xpthread_barrier_wait (&b2);
aa75f64c 1189
fa66f341 1190 xpthread_barrier_wait (&b2);
aa75f64c
UD
1191
1192 pthread_cleanup_push (cl, NULL);
1193
1194 fdatasync (tempfd);
1195
1196 pthread_cleanup_pop (0);
1197
fa66f341 1198 FAIL_EXIT1 ("fdatasync returned");
aa75f64c
UD
1199}
1200
1201
047aec8f
UD
1202static void *
1203tf_msync (void *arg)
1204{
1205 if (arg == NULL)
1206 // XXX If somebody can provide a portable test case in which msync()
1207 // blocks we can enable this test to run in both rounds.
1208 abort ();
1209
1210 tempfd = open ("Makefile", O_RDONLY);
1211 if (tempfd == -1)
fa66f341 1212 FAIL_EXIT1 ("open (\"Makefile\", O_RDONLY): %m");
047aec8f 1213
fa66f341 1214 void *p = xmmap (NULL, 10, PROT_READ, MAP_SHARED, tempfd);
047aec8f 1215
fa66f341
AZ
1216 xpthread_barrier_wait (&b2);
1217
1218 xpthread_barrier_wait (&b2);
047aec8f
UD
1219
1220 pthread_cleanup_push (cl, NULL);
1221
1222 msync (p, 10, 0);
1223
1224 pthread_cleanup_pop (0);
1225
fa66f341 1226 FAIL_EXIT1 ("msync returned");
047aec8f
UD
1227}
1228
1229
f23b30e2
UD
1230static void *
1231tf_sendto (void *arg)
1232{
1233 if (arg == NULL)
1234 // XXX If somebody can provide a portable test case in which sendto()
1235 // blocks we can enable this test to run in both rounds.
1236 abort ();
1237
1238 struct sockaddr_un sun;
1239
1240 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1241 if (tempfd == -1)
fa66f341 1242 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
f23b30e2
UD
1243
1244 int tries = 0;
1245 do
1246 {
fa66f341 1247 TEST_VERIFY_EXIT (tries++ < 10);
f23b30e2
UD
1248
1249 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-6-XXXXXX");
fa66f341 1250 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
f23b30e2
UD
1251
1252 sun.sun_family = AF_UNIX;
1253 }
1254 while (bind (tempfd, (struct sockaddr *) &sun,
1255 offsetof (struct sockaddr_un, sun_path)
1256 + strlen (sun.sun_path) + 1) != 0);
1257 tempfname = strdup (sun.sun_path);
1258
1259 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1260 if (tempfd2 == -1)
fa66f341 1261 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
f23b30e2 1262
fa66f341 1263 xpthread_barrier_wait (&b2);
f23b30e2 1264
fa66f341 1265 xpthread_barrier_wait (&b2);
f23b30e2
UD
1266
1267 pthread_cleanup_push (cl, NULL);
1268
1269 char mem[1];
1270
1271 sendto (tempfd2, mem, arg == NULL ? sizeof (mem) : 1, 0,
1272 (struct sockaddr *) &sun,
1273 offsetof (struct sockaddr_un, sun_path) + strlen (sun.sun_path) + 1);
1274
1275 pthread_cleanup_pop (0);
1276
fa66f341 1277 FAIL_EXIT1 ("sendto returned");
f23b30e2
UD
1278}
1279
1280
1281static void *
1282tf_sendmsg (void *arg)
1283{
1284 if (arg == NULL)
1285 // XXX If somebody can provide a portable test case in which sendmsg()
1286 // blocks we can enable this test to run in both rounds.
1287 abort ();
1288
1289 struct sockaddr_un sun;
1290
1291 tempfd = socket (AF_UNIX, SOCK_DGRAM, 0);
1292 if (tempfd == -1)
fa66f341 1293 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
f23b30e2
UD
1294
1295 int tries = 0;
1296 do
1297 {
fa66f341 1298 TEST_VERIFY_EXIT (tries++ < 10);
f23b30e2
UD
1299
1300 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-7-XXXXXX");
fa66f341 1301 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
f23b30e2
UD
1302
1303 sun.sun_family = AF_UNIX;
1304 }
1305 while (bind (tempfd, (struct sockaddr *) &sun,
1306 offsetof (struct sockaddr_un, sun_path)
1307 + strlen (sun.sun_path) + 1) != 0);
1308 tempfname = strdup (sun.sun_path);
1309
1310 tempfd2 = socket (AF_UNIX, SOCK_DGRAM, 0);
1311 if (tempfd2 == -1)
fa66f341 1312 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_DGRAM, 0): %m");
f23b30e2 1313
fa66f341 1314 xpthread_barrier_wait (&b2);
f23b30e2 1315
fa66f341 1316 xpthread_barrier_wait (&b2);
f23b30e2
UD
1317
1318 pthread_cleanup_push (cl, NULL);
1319
1320 char mem[1];
1321 struct iovec iov[1];
1322 iov[0].iov_base = mem;
1323 iov[0].iov_len = 1;
1324
1325 struct msghdr m;
1326 m.msg_name = &sun;
1327 m.msg_namelen = (offsetof (struct sockaddr_un, sun_path)
1328 + strlen (sun.sun_path) + 1);
1329 m.msg_iov = iov;
1330 m.msg_iovlen = 1;
1331 m.msg_control = NULL;
1332 m.msg_controllen = 0;
1333
1334 sendmsg (tempfd2, &m, 0);
1335
1336 pthread_cleanup_pop (0);
1337
fa66f341 1338 FAIL_EXIT1 ("sendmsg returned");
f23b30e2
UD
1339}
1340
1341
1342static void *
1343tf_creat (void *arg)
1344{
1345 if (arg == NULL)
1346 // XXX If somebody can provide a portable test case in which sendmsg()
1347 // blocks we can enable this test to run in both rounds.
1348 abort ();
1349
fa66f341 1350 xpthread_barrier_wait (&b2);
f23b30e2 1351
fa66f341 1352 xpthread_barrier_wait (&b2);
f23b30e2
UD
1353
1354 pthread_cleanup_push (cl, NULL);
1355
1356 creat ("tmp/tst-cancel-4-should-not-exist", 0666);
1357
1358 pthread_cleanup_pop (0);
1359
fa66f341 1360 FAIL_EXIT1 ("creat returned");
f23b30e2
UD
1361}
1362
1363
1364static void *
1365tf_connect (void *arg)
1366{
1367 if (arg == NULL)
1368 // XXX If somebody can provide a portable test case in which connect()
1369 // blocks we can enable this test to run in both rounds.
1370 abort ();
1371
1372 struct sockaddr_un sun;
1373
1374 tempfd = socket (AF_UNIX, SOCK_STREAM, 0);
1375 if (tempfd == -1)
fa66f341 1376 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
f23b30e2
UD
1377
1378 int tries = 0;
1379 do
1380 {
fa66f341 1381 TEST_VERIFY_EXIT (tries++ < 10);
f23b30e2
UD
1382
1383 strcpy (sun.sun_path, "/tmp/tst-cancel4-socket-2-XXXXXX");
fa66f341 1384 TEST_VERIFY_EXIT (mktemp (sun.sun_path) != NULL);
f23b30e2
UD
1385
1386 sun.sun_family = AF_UNIX;
1387 }
1388 while (bind (tempfd, (struct sockaddr *) &sun,
1389 offsetof (struct sockaddr_un, sun_path)
1390 + strlen (sun.sun_path) + 1) != 0);
1391 tempfname = strdup (sun.sun_path);
1392
1393 listen (tempfd, 5);
1394
1395 tempfd2 = socket (AF_UNIX, SOCK_STREAM, 0);
1396 if (tempfd2 == -1)
fa66f341 1397 FAIL_EXIT1 ("socket (AF_UNIX, SOCK_STREAM, 0): %m");
f23b30e2 1398
fa66f341 1399 xpthread_barrier_wait (&b2);
f23b30e2
UD
1400
1401 if (arg != NULL)
fa66f341 1402 xpthread_barrier_wait (&b2);
f23b30e2
UD
1403
1404 pthread_cleanup_push (cl, NULL);
1405
1406 connect (tempfd2, (struct sockaddr *) &sun, sizeof (sun));
1407
1408 pthread_cleanup_pop (0);
1409
fa66f341 1410 FAIL_EXIT1 ("connect returned");
f23b30e2
UD
1411}
1412
1413
1414static void *
1415tf_tcdrain (void *arg)
1416{
1417 if (arg == NULL)
1418 // XXX If somebody can provide a portable test case in which tcdrain()
1419 // blocks we can enable this test to run in both rounds.
1420 abort ();
1421
fa66f341 1422 xpthread_barrier_wait (&b2);
f23b30e2
UD
1423
1424 if (arg != NULL)
fa66f341 1425 xpthread_barrier_wait (&b2);
f23b30e2
UD
1426
1427 pthread_cleanup_push (cl, NULL);
1428
1429 /* Regardless of stderr being a terminal, the tcdrain call should be
1430 canceled. */
1431 tcdrain (STDERR_FILENO);
1432
1433 pthread_cleanup_pop (0);
1434
fa66f341 1435 FAIL_EXIT1 ("tcdrain returned");
f23b30e2
UD
1436}
1437
1438
1439static void *
1440tf_msgrcv (void *arg)
1441{
483e95d0 1442 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
67060ef5 1443 if (tempmsg == -1)
fa66f341 1444 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
f23b30e2 1445
fa66f341 1446 xpthread_barrier_wait (&b2);
f23b30e2
UD
1447
1448 if (arg != NULL)
fa66f341 1449 xpthread_barrier_wait (&b2);
f23b30e2 1450
7d7ff54c
UD
1451 ssize_t s;
1452
f23b30e2
UD
1453 pthread_cleanup_push (cl, NULL);
1454
1455 struct
1456 {
1457 long int type;
1458 char mem[10];
1459 } m;
ca343e73
UD
1460 int randnr;
1461 /* We need a positive random number. */
1462 do
483e95d0 1463 randnr = random () % 64000;
ca343e73
UD
1464 while (randnr <= 0);
1465 do
1466 {
1467 errno = 0;
7d7ff54c 1468 s = msgrcv (tempmsg, (struct msgbuf *) &m, 10, randnr, 0);
ca343e73 1469 }
7d7ff54c 1470 while (errno == EIDRM || errno == EINTR);
f23b30e2
UD
1471
1472 pthread_cleanup_pop (0);
1473
67060ef5
UD
1474 msgctl (tempmsg, IPC_RMID, NULL);
1475
fa66f341 1476 FAIL_EXIT1 ("msgrcv returned %zd", s);
f23b30e2
UD
1477}
1478
1479
1480static void *
1481tf_msgsnd (void *arg)
1482{
1483 if (arg == NULL)
1484 // XXX If somebody can provide a portable test case in which msgsnd()
1485 // blocks we can enable this test to run in both rounds.
1486 abort ();
1487
483e95d0 1488 tempmsg = msgget (IPC_PRIVATE, 0666 | IPC_CREAT);
67060ef5 1489 if (tempmsg == -1)
fa66f341 1490 FAIL_EXIT1 ("msgget (IPC_PRIVATE, 0666 | IPC_CREAT): %m");
f23b30e2 1491
fa66f341 1492 xpthread_barrier_wait (&b2);
f23b30e2 1493
fa66f341 1494 xpthread_barrier_wait (&b2);
f23b30e2
UD
1495
1496 pthread_cleanup_push (cl, NULL);
1497
1498 struct
1499 {
1500 long int type;
1501 char mem[1];
1502 } m;
ca343e73
UD
1503 /* We need a positive random number. */
1504 do
483e95d0 1505 m.type = random () % 64000;
ca343e73 1506 while (m.type <= 0);
f23b30e2
UD
1507 msgsnd (tempmsg, (struct msgbuf *) &m, sizeof (m.mem), 0);
1508
1509 pthread_cleanup_pop (0);
1510
67060ef5
UD
1511 msgctl (tempmsg, IPC_RMID, NULL);
1512
fa66f341 1513 FAIL_EXIT1 ("msgsnd returned");
f23b30e2
UD
1514}
1515
1516
b39b6e0c 1517struct cancel_tests tests[] =
26676450 1518{
26676450
UD
1519 ADD_TEST (read, 2, 0),
1520 ADD_TEST (readv, 2, 0),
1521 ADD_TEST (select, 2, 0),
1522 ADD_TEST (pselect, 2, 0),
1523 ADD_TEST (poll, 2, 0),
7c65e900 1524 ADD_TEST (ppoll, 2, 0),
26676450
UD
1525 ADD_TEST (write, 2, 0),
1526 ADD_TEST (writev, 2, 0),
1527 ADD_TEST (sleep, 2, 0),
1528 ADD_TEST (usleep, 2, 0),
1529 ADD_TEST (nanosleep, 2, 0),
1530 ADD_TEST (wait, 2, 0),
1531 ADD_TEST (waitid, 2, 0),
1532 ADD_TEST (waitpid, 2, 0),
1533 ADD_TEST (sigpause, 2, 0),
1534 ADD_TEST (sigsuspend, 2, 0),
1535 ADD_TEST (sigwait, 2, 0),
1536 ADD_TEST (sigwaitinfo, 2, 0),
1537 ADD_TEST (sigtimedwait, 2, 0),
1538 ADD_TEST (pause, 2, 0),
1539 ADD_TEST (accept, 2, 0),
1540 ADD_TEST (send, 2, 0),
1541 ADD_TEST (recv, 2, 0),
1542 ADD_TEST (recvfrom, 2, 0),
1543 ADD_TEST (recvmsg, 2, 0),
4e778151 1544 ADD_TEST (preadv, 2, 1),
52bd9381 1545 ADD_TEST (preadv2, 2, 1),
af5fdf5a 1546 ADD_TEST (pwritev, 2, 1),
52bd9381 1547 ADD_TEST (pwritev2, 2, 1),
047aec8f
UD
1548 ADD_TEST (open, 2, 1),
1549 ADD_TEST (close, 2, 1),
1550 ADD_TEST (pread, 2, 1),
1551 ADD_TEST (pwrite, 2, 1),
1552 ADD_TEST (fsync, 2, 1),
aa75f64c 1553 ADD_TEST (fdatasync, 2, 1),
047aec8f 1554 ADD_TEST (msync, 2, 1),
f23b30e2
UD
1555 ADD_TEST (sendto, 2, 1),
1556 ADD_TEST (sendmsg, 2, 1),
1557 ADD_TEST (creat, 2, 1),
1558 ADD_TEST (connect, 2, 1),
1559 ADD_TEST (tcdrain, 2, 1),
1560 ADD_TEST (msgrcv, 2, 0),
1561 ADD_TEST (msgsnd, 2, 1),
26676450
UD
1562};
1563#define ntest_tf (sizeof (tests) / sizeof (tests[0]))
1564
b39b6e0c 1565#include "tst-cancel4-common.c"