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