From 66c75fa63aff40e9c587345b2cc6b8148e396de8 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Wed, 6 Aug 2025 20:36:05 +0000 Subject: [PATCH] freebsd-update: Fix the pkgbase check Even on a pkgbase system, it should be possible to use freebsd-update -j to upgrade a non-pkgbase jail, at least for the time being. However, the check_pkgbase() call came before get_params, so BASEDIR was always set to /. Make check_pkgbase() a pure function and call it after get_params(). While here, use pkg -r ${BASEDIR} instead of pkg -c ${BASEDIR} since the latter requires root privileges. freebsd-update is supposed to be run as root, but it doesn't actually check this that I can see, so let's not make that assumption here since it affects the result of the function (i.e., pkg -c ${BASEDIR} always fails as a non-root user). Reviewed by: des Fixes: 856e158dc4aa ("freebsd-update: improve pkgbase check") MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D51770 --- usr.sbin/freebsd-update/freebsd-update.sh | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh index ccd98a883dc..c388e76644d 100644 --- a/usr.sbin/freebsd-update/freebsd-update.sh +++ b/usr.sbin/freebsd-update/freebsd-update.sh @@ -1099,24 +1099,19 @@ IDS_check_params () { fetch_setup_verboselevel } -# Packaged base and freebsd-update are incompatible. Exit with an error if -# packaged base is in use. +# Return 0 if the system is managed using pkgbase, 1 otherwise. check_pkgbase() { # Packaged base requires that pkg is bootstrapped. - if ! pkg -c ${BASEDIR} -N >/dev/null 2>/dev/null; then - return + if ! pkg -r ${BASEDIR} -N >/dev/null 2>/dev/null; then + return 1 fi # uname(1) is used by pkg to determine ABI, so it should exist. # If it comes from a package then this system uses packaged base. - if ! pkg -c ${BASEDIR} which /usr/bin/uname >/dev/null; then - return + if ! pkg -r ${BASEDIR} which /usr/bin/uname >/dev/null; then + return 1 fi - cat <