From nobody Sat Jul 26 03:14:04 2025 X-Original-To: dev-commits-src-main@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 4bpqb06gncz62y3Q; Sat, 26 Jul 2025 03:14:04 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bpqb03GP1z3cKX; Sat, 26 Jul 2025 03:14:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753499644; 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=uD9ajMfonvAiyCRPUKgUxEHZtChwXUiyQWIo752uTEM=; b=diEzv7ws8fqmA7LOH9Cj8tvTaymamEDX0CPXVgAWPcM3F6sCYZpYg063DfDslizhc7fDYB Qn5BPVjZcNYJBqTtX1mA+8GfI0C7lUqvO0WY6rNGWkWpz5AicAormXQ8utGFtGx1IXHpO4 x3o2NTI1PtFq2Mcss/DFDnwYEy9NOeU6zSMtKM/KuDlcPUmnXTRwDgfDcupSX0HSOTJ9Uj ZnB2+PsaMNpghOgWRpnxgIhER8hc1hJzmKzDgjY8XNqZnCLPyW/0qc98kcwP86IpMNfkGd tJ4FgDtqPzm3mnHGpvee0ASLCDastlAmaiopBs5EJOwPLpJFS8BV61UHTUqfqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753499644; 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=uD9ajMfonvAiyCRPUKgUxEHZtChwXUiyQWIo752uTEM=; b=GkEARHC2auLZ6BMGgURY3a5ITmaXAoMkhqRthYZqu4KNMTf1hcODfTcxmjBnOi5/1lewvi uBxaVSvHXmX/UMFXgHJZDqIF5ctfYNAZnZYLC/q78N7DYRO6+VcnIhBJx+EyQp3bgixHru svGyZF6AKAfvYAkgO1E4hRNri3vWJFcTULuj0E/G34ohQBitarY8LXCTfRQz3BXskWnfK9 7VUbt67nK6dXn0dozGOeYPc6NTDHNYFCENnVlG9/DKFfknmSqvraqMVOkfbN7Qi9g47f07 hETidF/BvbPv/kbHHwTyQs5iJYt8HUtH9f6JJCH/2b6UZPoe+wyqrncNA2E8kg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753499644; a=rsa-sha256; cv=none; b=azEi5CqQ9VWw/ACscn/j3XtJTrLWUgE0D/pCxGHxoMb7yC9x3a3eATK/NI9PJfqRX2oBJl LmJiyblKhDY9JL33a8lFWwvLy27e4MPRNYES8OrGlSpGDbSiBEuAO7hIbdbtQvE4GPI+xH t8U3T7lDyV7di8c5UUCoZ1eZqIWK5VYeSNp1QdJye+ho5ATeJDoFICkNFrvqjCumIZj3/A zNj78ANLKQmUDdeb9zTOrh1o/OkVXt1Qb/cKvmWwwmpnPO0xIfxYagwh98Tpn4AiMOKmj/ mwCjYv05QHLrfp4DQD6s+Mv1X9ooOuanzAAt+F/+i+el7LrvWl7XKlttdEyGAQ== 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 4bpqb01DL4z1BhL; Sat, 26 Jul 2025 03:14:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56Q3E4KY002839; Sat, 26 Jul 2025 03:14:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56Q3E4PE002836; Sat, 26 Jul 2025 03:14:04 GMT (envelope-from git) Date: Sat, 26 Jul 2025 03:14:04 GMT Message-Id: <202507260314.56Q3E4PE002836@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: cfc595f4a05e - main - jail: tests: cleanup the commands test a bit List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cfc595f4a05ed6fc690b17adee967e652b8636b3 Auto-Submitted: auto-generated The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=cfc595f4a05ed6fc690b17adee967e652b8636b3 commit cfc595f4a05ed6fc690b17adee967e652b8636b3 Author: Kyle Evans AuthorDate: 2025-07-26 03:13:40 +0000 Commit: Kyle Evans CommitDate: 2025-07-26 03:13:40 +0000 jail: tests: cleanup the commands test a bit We shouldn't be doing setup in a head() function, as this can cause various problems. For instance, in this case, it caused test listing to fail in some cases if we didn't get to execute the cleanup properly by complaining to stderr if the directory could not be created. Switch to using atf_check for sanity checking stdout; most of these expressions are self-explanatory and will make it clear what the problem is. commands.jail.conf contains a hard-coded path that we can avoid, which is probably good to avoid weird conflicts if other tests try to copy it and do the same. Just make a copy of our jail.conf and add the test's $PWD to it to get a generally unique jail root. Finally, simplify the cleanup handler a bit. Reviewed by: jamie Differential Revision: https://reviews.freebsd.org/D51501 --- usr.sbin/jail/tests/commands.jail.conf | 2 -- usr.sbin/jail/tests/jail_basic_test.sh | 35 +++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/usr.sbin/jail/tests/commands.jail.conf b/usr.sbin/jail/tests/commands.jail.conf index afd56d1fa5d6..ad152a28b7fe 100644 --- a/usr.sbin/jail/tests/commands.jail.conf +++ b/usr.sbin/jail/tests/commands.jail.conf @@ -4,6 +4,4 @@ exec.prestart = "echo START"; exec.poststart = "env"; persist; -path = "/tmp/test_${name}_root"; - basejail {} diff --git a/usr.sbin/jail/tests/jail_basic_test.sh b/usr.sbin/jail/tests/jail_basic_test.sh index 6498eb1c1fdc..f3c8be4a6595 100755 --- a/usr.sbin/jail/tests/jail_basic_test.sh +++ b/usr.sbin/jail/tests/jail_basic_test.sh @@ -129,38 +129,43 @@ commands_head() { atf_set descr 'Commands jail test' atf_set require.user root - mkdir /tmp/test_basejail_root } commands_body() { + cp "$(atf_get_srcdir)/commands.jail.conf" jail.conf + echo "path = \"$PWD\";" >> jail.conf + # exec.prestart (START) and exec.poststart (env) - atf_check -s exit:0 -o save:stdout -e empty \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail - grep -E '^START$' stdout || atf_fail "exec.prestart output not found" - grep -E '^JID=[0-9]+' stdout || atf_fail "JID not found in exec.poststart env output" - grep -E '^JNAME=basejail$' stdout || atf_fail "JNAME not found in exec.poststart env output" - grep -E '^JPATH=/tmp/test_basejail_root$' stdout || atf_fail "JPATH not found in exec.poststart env output" + atf_check -o save:stdout -e empty \ + jail -f jail.conf -qc basejail + + # exec.prestart output is missing + atf_check grep -qE '^START$' stdout + # JID was not set in the exec.poststart env + atf_check grep -qE '^JID=[0-9]+' stdout + # JNAME was not set in the exec.poststart env + atf_check grep -qE '^JNAME=basejail$' stdout + # JPATH was not set in the exec.poststart env + atf_check grep -qE "^JPATH=$PWD$" stdout # exec.prestop by jailname atf_check -s exit:0 -o inline:"STOP\n" \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qr basejail + jail -f jail.conf -qr basejail # exec.prestop by jid - jail -f $(atf_get_srcdir)/commands.jail.conf -qc basejail + jail -f jail.conf -qc basejail atf_check -s exit:0 -o inline:"STOP\n" \ - jail -f $(atf_get_srcdir)/commands.jail.conf -qr `jls -j basejail jid` + jail -f jail.conf -qr `jls -j basejail jid` } -commands_cleanup() +commands_cleanup() { - jls -j basejail > /dev/null 2>&1 - if [ $? -e 0 ] - then + if jls -j basejail > /dev/null 2>&1; then jail -r basejail fi - rmdir /tmp/test_basejail_root } + atf_init_test_cases() { atf_add_test_case "basic"