From nobody Wed Oct 04 11:23:44 2023 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 4S0sl45xzWz4vkZ2; Wed, 4 Oct 2023 11:23:44 +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 4S0sl45NjBz4brj; Wed, 4 Oct 2023 11:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696418624; 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=w9nAsIKFRdNinjquat/Bm6akci/B2WBNEMlKQBI7w/c=; b=YnPdnE1sB+rmClIm/IaFOWqy/DJoFTIxtmoEpWVb/B+S2s09XEg+S0OKHySqm7cw0oqSif 62ZBzajgrLobJsCXlw+ZDORUH9Ek5cUtr+6c1J3i2u3ow0VQB7PSIlldV9xyg2cZrnIqAh lTjZ2kO9D4eiWPHvutwceDFpDGEwXQhx3TQOqye+JXiuXmHlx0Rtv8pcxhIkv8Csu9NBCS hjsmt4Io4XXhjl4tkjSUi7xNFgVY14zqIvzWpayfBKFIKiJ3aKIbxgC2ugJXlfxRt1e2OG FLuU6TyYUxqYbR+OC3Lp2BfNKWke2wx2dT72bxv95g2Kf+Dw8ansT3Vltmuidg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696418624; a=rsa-sha256; cv=none; b=UCPNl/pfsfMmMXtBIpJDfnpmsALra+nKMMcI0KGhj1sxEeE9V2PPEUb2dZLzvwvYUYFyvm zZ+MUy35scZrNxemEiOWEEzMSt5I7hldIP5Y6yRwwIuc2ECGmf9rdUhdAXLP+JmQipzCjq PMneLy9C1XbSaBYyA5x0RkZ3kw6ulV3ZK01l794Lnte+L5HxcayFLX0+C9jVkX3ia+YVo0 qJU8ycYMXqtEYWXsTE0mMKheRPJjxdDdc29goPoPTH+TS9q2x3bxL8Oa1NIa/oWPFy0nhZ /90G2MBCL4d+Oq+WsADAAg2rTr1+Nr1jb9c47t1otV6iV0wX56CMMptEtW6pBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696418624; 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=w9nAsIKFRdNinjquat/Bm6akci/B2WBNEMlKQBI7w/c=; b=WFNBhfNxQAfFd4L3eLoxkT6Pg0m7HZoxmzcFG6kYhdvUztvgu66N2k9YyeWXoCj5ODCbbS 7o4i97Sji4NWul9BhAqvu8CVSQSHk9CIBJImzo4Qsjx4tY1fiM2q9uCBf7jgGOFYGVyvmE ysSC0THC2K3u3NUArUPTsGav8pZQrGPpxaAvrUS4mU5bkIUKZxVWYMhXreFZViareUojkj 8h+5mOUxCwViPE536ziHGkABp2MQ932LYGOFoY8DjwxxlT6BDG7SuGnZ9fq1HtlC+Pd7qb QFnVqUDfXhiSwIoyvCZ0MeK+2TDKghY+9vUzG5M4/5gHOfmrclbByM16C1fvOQ== 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 4S0sl44VRPzbdX; Wed, 4 Oct 2023 11:23:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 394BNicg084737; Wed, 4 Oct 2023 11:23:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 394BNiRV084734; Wed, 4 Oct 2023 11:23:44 GMT (envelope-from git) Date: Wed, 4 Oct 2023 11:23:44 GMT Message-Id: <202310041123.394BNiRV084734@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Piotrowski <0mp@FreeBSD.org> Subject: git: 220af70281c5 - stable/13 - rc: Start testing the rc(8) framework (beginning with *_oomprotect) 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: 0mp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 220af70281c5c04610f6bf4ce904e269d1532992 Auto-Submitted: auto-generated The branch stable/13 has been updated by 0mp: URL: https://cgit.FreeBSD.org/src/commit/?id=220af70281c5c04610f6bf4ce904e269d1532992 commit 220af70281c5c04610f6bf4ce904e269d1532992 Author: Mateusz Piotrowski <0mp@FreeBSD.org> AuthorDate: 2022-07-07 18:24:27 +0000 Commit: Mateusz Piotrowski <0mp@FreeBSD.org> CommitDate: 2023-10-04 11:11:18 +0000 rc: Start testing the rc(8) framework (beginning with *_oomprotect) This change adds 2 tests to make sure that the *_oomprotect variable sets the protection against OOM killer properly within rc(8) scripts. This is also adding the first tests for the rc(8) framework. More tests will be added as we go. PR: 256148 Approved by: des MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D35745 (cherry picked from commit e7437ae907c89bf85a99c5cbb7ddd194a1ff1354) --- etc/mtree/BSD.tests.dist | 2 + libexec/rc/Makefile | 3 ++ libexec/rc/tests/Makefile | 3 ++ libexec/rc/tests/rc_subr_test.sh | 103 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 39d1e7801619..46a305aec62d 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -429,6 +429,8 @@ atf-sh .. .. + rc + .. rtld-elf .. tftpd diff --git a/libexec/rc/Makefile b/libexec/rc/Makefile index 9383ab124839..4f9d374c8f15 100644 --- a/libexec/rc/Makefile +++ b/libexec/rc/Makefile @@ -23,4 +23,7 @@ CONFETCDEFAULTSPACKAGE= rc SUBDIR+= rc.d +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/libexec/rc/tests/Makefile b/libexec/rc/tests/Makefile new file mode 100644 index 000000000000..c44c6db90b77 --- /dev/null +++ b/libexec/rc/tests/Makefile @@ -0,0 +1,3 @@ +ATF_TESTS_SH+= rc_subr_test + +.include diff --git a/libexec/rc/tests/rc_subr_test.sh b/libexec/rc/tests/rc_subr_test.sh new file mode 100644 index 000000000000..0ca790e39a14 --- /dev/null +++ b/libexec/rc/tests/rc_subr_test.sh @@ -0,0 +1,103 @@ +# +# Copyright 2022 Mateusz Piotrowski <0mp@FreeBSD.org> +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +atf_test_case oomprotect_all +oomprotect_all_head() +{ + atf_set "descr" "Verify that \${name}_oomprotect=all protects " \ + "the command and all its current and future children" + atf_set "require.user" "root" # For protect(1). +} + +oomprotect_all_body() +{ + __name="$(atf_get ident)" + __pidfile="$(mktemp -t "${__name}.pid")" + __childpidfile="$(mktemp -t "${__name}.childpid")" + __script=$(mktemp -t "${__name}.script") + + cat >> "$__script" <<-'LITERAL' + . /etc/rc.subr + name="$1" + pidfile="$2" + _childpidfile="$3" + _rc_arg="$4" + setvar "${name}_oomprotect" all + command="/usr/sbin/daemon" + command_args="-P $pidfile -p $_childpidfile -- /bin/sleep 5" + run_rc_command "$_rc_arg" + LITERAL + + atf_check -s exit:0 -o inline:"Starting ${__name}.\n" -e empty \ + /bin/sh "$__script" "$__name" "$__pidfile" "$__childpidfile" onestart + atf_check -s exit:0 -o match:'^..1..... .......1$' -e empty \ + ps -p "$(cat "$__pidfile")" -ax -o flags,flags2 + atf_check -s exit:0 -o match:'^..1..... .......1$' -e empty \ + ps -p "$(cat "$__childpidfile")" -ax -o flags,flags2 + atf_check -s exit:0 -o ignore -e empty \ + /bin/sh "$__script" "$__name" "$__pidfile" "$__childpidfile" onestop +} + +atf_test_case oomprotect_yes +oomprotect_yes_head() +{ + atf_set "descr" "Verify that \${name}_oomprotect=yes protects " \ + "the command but not its children" + atf_set "require.user" "root" # For protect(1). +} + +oomprotect_yes_body() +{ + __name="$(atf_get ident)" + __pidfile="$(mktemp -t "${__name}.pid")" + __script=$(mktemp -t "${__name}.script") + + cat >> "$__script" <<-'LITERAL' + . /etc/rc.subr + name="$1" + pidfile="$2" + _rc_arg="$3" + setvar "${name}_oomprotect" yes + procname="/bin/sleep" + command="/usr/sbin/daemon" + command_args="-p $pidfile -- $procname 5" + run_rc_command "$_rc_arg" + LITERAL + + atf_check -s exit:0 -o inline:"Starting ${__name}.\n" -e empty \ + /bin/sh "$__script" "$__name" "$__pidfile" onestart + atf_check -s exit:0 -o match:'^..1..... .......0$' -e empty \ + ps -p "$(cat "$__pidfile")" -ax -o flags,flags2 + atf_check -s exit:0 -o ignore -e empty \ + /bin/sh "$__script" "$__name" "$__pidfile" onestop +} + +atf_init_test_cases() +{ + atf_add_test_case oomprotect_all + atf_add_test_case oomprotect_yes +}