diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c --- a/tests/sys/kern/unix_passfd_test.c +++ b/tests/sys/kern/unix_passfd_test.c @@ -118,6 +118,17 @@ return (n); } +static int +openfiles(void) +{ + int files; + size_t len = sizeof(files); + + ATF_REQUIRE(sysctlbyname("kern.openfiles", &files, &len, NULL, 0) == 0); + + return (files); +} + static void putfds(char *buf, int fd, int nfds) { @@ -336,6 +347,28 @@ closesocketpair(fd); } +/* + * Send file then shutdown receive side to exercise unp_dispose() call + * via soshutdown(). Check that shutdown(SHUT_RD) would gc the file + * reference sitting in the receive buffer. There is no good way of + * checking that except using global open file count. + */ +ATF_TC_WITHOUT_HEAD(send_and_shutdown); +ATF_TC_BODY(send_and_shutdown, tc) +{ + int fd[2], putfd, nfiles; + + domainsocketpair(fd); + tempfile(&putfd); + sendfd(fd[0], putfd); + nfiles = openfiles(); + close(putfd); + ATF_REQUIRE(openfiles() == nfiles); + shutdown(fd[1], SHUT_RD); + ATF_REQUIRE(openfiles() == nfiles - 1); + closesocketpair(fd); +} + /* * Send two files. Then receive them. Make sure they are returned in the * right order, and both get there. @@ -722,6 +755,7 @@ ATF_TP_ADD_TC(tp, simple_send_fd_msg_cmsg_cloexec); ATF_TP_ADD_TC(tp, send_and_close); ATF_TP_ADD_TC(tp, send_and_cancel); + ATF_TP_ADD_TC(tp, send_and_shutdown); ATF_TP_ADD_TC(tp, two_files); ATF_TP_ADD_TC(tp, bundle); ATF_TP_ADD_TC(tp, bundle_cancel);