The branch main has been updated by kevans:

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

commit b81fd3fc8b20eaad64b5c41826432124fd92d6a7
Author:     Kyle Evans <kev...@freebsd.org>
AuthorDate: 2025-08-16 17:39:47 +0000
Commit:     Kyle Evans <kev...@freebsd.org>
CommitDate: 2025-08-16 17:39:59 +0000

    jail: fix backfilling the "name" for jid-named jails
    
    Using the cfparam variant of add_param() will actually copy the name and
    flags from the passed-in param, which I hadn't considered.  We actually
    want the name/flags from the "name" param so that we can do variable
    expansion against it right after that -- otherwise it cannot be found,
    since variable expansion actually searches by name.
    
    While we're here, `jls -e` was the intermediate name for `jls -c` that
    never saw the light of the day.  Fix our existence test.
    
    Reviewed by:    jamie
    Fixes:  02944d8c49 ("jail: consistently populate the KP_JID [...]")
    Differential Revision:  https://reviews.freebsd.org/D51831
---
 usr.sbin/jail/config.c                 |  2 +-
 usr.sbin/jail/tests/jail_basic_test.sh | 15 ++++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/usr.sbin/jail/config.c b/usr.sbin/jail/config.c
index 70de82e662e7..1bad04ccde68 100644
--- a/usr.sbin/jail/config.c
+++ b/usr.sbin/jail/config.c
@@ -189,7 +189,7 @@ load_config(const char *cfname)
                 * jail is created or found.
                 */
                if (j->intparams[KP_NAME] == NULL)
-                       add_param(j, j->intparams[KP_JID], KP_NAME, NULL);
+                       add_param(j, NULL, KP_NAME, j->name);
 
                /* Resolve any variable substitutions. */
                pgen = 0;
diff --git a/usr.sbin/jail/tests/jail_basic_test.sh 
b/usr.sbin/jail/tests/jail_basic_test.sh
index 509900e8569c..6802da7b049a 100755
--- a/usr.sbin/jail/tests/jail_basic_test.sh
+++ b/usr.sbin/jail/tests/jail_basic_test.sh
@@ -198,7 +198,7 @@ clean_jails()
        fi
 
        while read jail; do
-               if jls -e -j "$jail"; then
+               if jls -c -j "$jail"; then
                        jail -r "$jail"
                fi
        done < jails.lst
@@ -211,10 +211,23 @@ jid_name_set_body()
        echo "basejail" >> jails.lst
        echo "$jid { name = basejail; persist; }" > jail.conf
        atf_check -o match:"$jid: created" jail -f jail.conf -c "$jid"
+       # Confirm that we didn't override the explicitly-set name with the jid
+       # as the name.
+       atf_check -o match:"basejail" jls -j "$jid" name
+       atf_check -o match:"$jid: removed" jail -f jail.conf -r "$jid"
+
+       echo "$jid { host.hostname = \"\${name}\"; persist; }" > jail.conf
+       atf_check -o match:"$jid: created" jail -f jail.conf -c "$jid"
+       # Confirm that ${name} expanded and expanded correctly to the
+       # jid-implied name.
+       atf_check -o match:"$jid" jls -j "$jid" host.hostname
        atf_check -o match:"$jid: removed" jail -f jail.conf -r "$jid"
 
        echo "basejail { jid = $jid; persist; }" > jail.conf
        atf_check -o match:"basejail: created" jail -f jail.conf -c basejail
+       # Confirm that our jid assigment in the definition worked out and we
+       # did in-fact create the jail there.
+       atf_check -o match:"$jid" jls -j "basejail" jid
        atf_check -o match:"basejail: removed" jail -f jail.conf -r basejail
 }
 

Reply via email to