]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/darwintests/socket_poll_close_25786011.c
xnu-4570.1.46.tar.gz
[apple/xnu.git] / tools / tests / darwintests / socket_poll_close_25786011.c
1 #include <darwintest.h>
2 #include <poll.h>
3 #include <sys/socket.h>
4 #include <unistd.h>
5
6 T_DECL(socket_poll_close_25786011, "Tests an invalid poll call to a socket and then calling close.", T_META_LTEPHASE(LTE_POSTINIT))
7 {
8 int my_socket, ret;
9
10 my_socket = socket(PF_LOCAL, SOCK_STREAM, 0);
11 T_WITH_ERRNO; T_ASSERT_TRUE(my_socket > 0, "create socket");
12
13 /*
14 * Setup a pollfd that we know will return an error when we try
15 * to create a knote for it. We specify a BSD vnode specific event
16 * for a socket.
17 */
18 struct pollfd my_pollfd = {
19 .fd = my_socket,
20 .events = POLLEXTEND
21 };
22
23 /*
24 * Previously the call to kevent_register() in the kernel from this call
25 * would leak an iocount reference on the fileproc, which would cause any
26 * subsequent calls to close() on the associated fd to block indefinitely.
27 */
28 ret = poll(&my_pollfd, 1, 0);
29 T_WITH_ERRNO; T_ASSERT_TRUE(ret == 1, "poll returned %d", ret);
30
31 ret = close(my_socket);
32 T_ASSERT_POSIX_ZERO(ret, "close on socket with fd %d\n", my_socket);
33
34 T_PASS("socket_poll_close_25786011 PASSED");
35 }