]>
git.saurik.com Git - apple/xnu.git/blob - tests/kqueue_close.c
7 #include <darwintest.h>
9 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
12 * <rdar://problem/30231213> close() of kqueue FD races with kqueue_scan park
14 * When close concurrent with poll goes wrong, the close hangs
15 * and the kevent never gets any more events.
18 /* Both events should fire at about the same time */
19 static uint32_t timeout_ms
= 10;
22 poll_kqueue(void *arg
)
27 .filter
= EVFILT_TIMER
,
32 int rv
= kevent(fd
, &kev
, 1, NULL
, 0, NULL
);
34 if (rv
== -1 && errno
== EBADF
) {
35 /* The close may race with this thread spawning */
36 T_LOG("kqueue already closed?");
39 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "kevent");
42 while ((rv
= kevent(fd
, NULL
, 0, &kev
, 1, NULL
)) == 1) {
46 if (rv
!= -1 || errno
!= EBADF
) {
47 T_ASSERT_POSIX_SUCCESS(rv
, "fd should be closed");
57 T_QUIET
; T_ASSERT_POSIX_SUCCESS(fd
, "kqueue");
60 int rv
= pthread_create(&thread
, NULL
, poll_kqueue
,
61 (void *)(uintptr_t)fd
);
62 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "pthread_create");
64 usleep(timeout_ms
* 1000);
67 T_ASSERT_POSIX_SUCCESS(rv
, "close");
69 rv
= pthread_join(thread
, NULL
);
70 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "pthread_join");
73 T_DECL(kqueue_close_race
, "Races kqueue close with kqueue process",
74 T_META_LTEPHASE(LTE_POSTINIT
), T_META_TIMEOUT(5))
76 for (uint32_t i
= 1; i
< 100; i
++) {