From nobody Mon May 09 17:55:07 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 060DD1AD8978; Mon, 9 May 2022 17:55:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KxpjS1gsrz4sTJ; Mon, 9 May 2022 17:55:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652118908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1xpjV/YJolqUZInz+ZY0bkHnvuu3fl92ba0x4hcgls8=; b=cuuWNTXOiSHwf2aMbo11PV1pysD1MMfn2+504+n+KtjzsSKDKDiKjWStY2M/S+zIK5tfgy S36I1BeX4Du8oJqrZm+o3l1VyVPmBIdGpDYhUmOk1Vg6Lyzn0eN5iDB8/eVcnBhGs9/fBD RTaMOg47Ny65RHR2KzTsmfeyUgywVo/yVmkHiaUkJiAAQ5suTTXimyu3GRGqk+oZHDIW+7 S913Y5UcVPTMRCAFByT72DVaE4sOWLVCUzT3HZ/8THcS2C0dBilBSQjugzZbFJR6MiBtEN TwRmzQ2DoTCC5AFpy3EGs8r8LQ8tk5dCfWO817OKqzqaK8K1ldjYZBsxcapoLw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0FF331581D; Mon, 9 May 2022 17:55:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 249Ht7DY061124; Mon, 9 May 2022 17:55:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 249Ht7uo061123; Mon, 9 May 2022 17:55:07 GMT (envelope-from git) Date: Mon, 9 May 2022 17:55:07 GMT Message-Id: <202205091755.249Ht7uo061123@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 2400c536b478 - main - tests/unix_passfd: add test for shutdown(2) on a buffer with an fd List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2400c536b478b1d218507d29ee74b309522d65f5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652118908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=1xpjV/YJolqUZInz+ZY0bkHnvuu3fl92ba0x4hcgls8=; b=oTsOL5SoUmzdrkzbMN1ZFmYMmtqZqws4/RVTnx3Aotv97Bbnki42RY5G4FBXDRZSGibcvR +tGU7NgxYvq/rxKQVbBDDPx65QPeqj+mOtGKS14XZC/R+PDqDUfC3oztF3Cv5eAvlEnZS6 R9rHXjxqGeCl7KkBOrfeix+zEDyV0df5nNWB6RBSxviz74TJ91d1hCeJFv0W//bUXKwB0X Rg1r2bANUKUyb6cHNxkqX2kO7dIViqZVNpCC6CO03kQ5bntrSYvtT7+5Yt4n8hIt5x8Sme B0bxzVWp89DihWwczeSjhXw6g5GEy6gj31CjGYff03AV54EUF4JiGk+aDVsYdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652118908; a=rsa-sha256; cv=none; b=A3f8KchalZN5FEbVtgnt57MfaSQWwjWwW3D3faoZlXq9+3kTKxP0jF6duii/JvuZNGhFQa LJAz8RwsTASXoM4N1v0dvGZcIGsJTExdYM8/BM5+oJsuzBUQ9/xmy3+RkZA9AH17S5+h+6 BnTnHOzVYWfuhrNFWEdd177PC6Bg4iYGU1BQ26k0PRJNIUDmmkrUR08+019PTH5RII/73N 5jUC6/xwO1M66BiuIEQ8ugHpnPyWoGCo6+LvOEKYOYYJw6e/aa2cF2E73wqsSnrSJrRZds A8W1vY/Kvng2+7BHiYnXCrHII6H8dDHMol67kqFgT2+t0LQz/BDAyelhrSwO0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=2400c536b478b1d218507d29ee74b309522d65f5 commit 2400c536b478b1d218507d29ee74b309522d65f5 Author: Gleb Smirnoff AuthorDate: 2022-05-09 17:42:48 +0000 Commit: Gleb Smirnoff 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);