Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 May 2022 17:55:07 GMT
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 2400c536b478 - main - tests/unix_passfd: add test for shutdown(2) on a buffer with an fd
Message-ID:  <202205091755.249Ht7uo061123@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=2400c536b478b1d218507d29ee74b309522d65f5

commit 2400c536b478b1d218507d29ee74b309522d65f5
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2022-05-09 17:42:48 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2022-05-09 17:42:48 +0000

    tests/unix_passfd: add test for shutdown(2) on a buffer with an fd
    
    This has two goals:
    - Exercize call to unp_dispose() via soshutdown() instead of sofree()
    - Make sure that shutdown indeed dereferences the fd stored
    
    Reviewed by:            markj
    Differential revision:  https://reviews.freebsd.org/D35122
---
 tests/sys/kern/unix_passfd_test.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c
index 2b5cdde012c1..13b569479af8 100644
--- a/tests/sys/kern/unix_passfd_test.c
+++ b/tests/sys/kern/unix_passfd_test.c
@@ -118,6 +118,17 @@ getnfds(void)
 	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 @@ ATF_TC_BODY(send_and_cancel, tc)
 	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_TCS(tp)
 	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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202205091755.249Ht7uo061123>