]>
git.saurik.com Git - apple/xnu.git/blob - tests/kqueue_close.c
7 #include <darwintest.h>
10 * <rdar://problem/30231213> close() of kqueue FD races with kqueue_scan park
12 * When close concurrent with poll goes wrong, the close hangs
13 * and the kevent never gets any more events.
16 /* Both events should fire at about the same time */
17 static uint32_t timeout_ms
= 10;
20 poll_kqueue(void *arg
)
25 .filter
= EVFILT_TIMER
,
30 int rv
= kevent(fd
, &kev
, 1, NULL
, 0, NULL
);
32 if (rv
== -1 && errno
== EBADF
) {
33 /* The close may race with this thread spawning */
34 T_LOG("kqueue already closed?");
37 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "kevent");
40 while ((rv
= kevent(fd
, NULL
, 0, &kev
, 1, NULL
)) == 1) {
44 if (rv
!= -1 || errno
!= EBADF
) {
45 T_ASSERT_POSIX_SUCCESS(rv
, "fd should be closed");
55 T_QUIET
; T_ASSERT_POSIX_SUCCESS(fd
, "kqueue");
58 int rv
= pthread_create(&thread
, NULL
, poll_kqueue
,
59 (void *)(uintptr_t)fd
);
60 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "pthread_create");
62 usleep(timeout_ms
* 1000);
65 T_ASSERT_POSIX_SUCCESS(rv
, "close");
67 rv
= pthread_join(thread
, NULL
);
68 T_QUIET
; T_ASSERT_POSIX_SUCCESS(rv
, "pthread_join");
71 T_DECL(kqueue_close_race
, "Races kqueue close with kqueue process",
72 T_META_LTEPHASE(LTE_POSTINIT
), T_META_TIMEOUT(5))
74 for (uint32_t i
= 1 ; i
< 100 ; i
++) {