Date: Sat, 25 Apr 2026 16:22:23 +0000 From: Enji Cooper <ngie@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 99b65c8b4772 - stable/14 - release.sh: add chroot cleanup routine Message-ID: <69ecea3f.448b4.579a1ad@gitrepo.freebsd.org>
index | next in thread | raw e-mail
The branch stable/14 has been updated by ngie: URL: https://cgit.FreeBSD.org/src/commit/?id=99b65c8b47724952a22186b7214523fadd012560 commit 99b65c8b47724952a22186b7214523fadd012560 Author: Enji Cooper <ngie@FreeBSD.org> AuthorDate: 2026-03-22 02:57:25 +0000 Commit: Enji Cooper <ngie@FreeBSD.org> CommitDate: 2026-04-25 16:22:18 +0000 release.sh: add chroot cleanup routine The chroot_cleanup routine handles any cleanup needed post-chroot_setup, etc. This consists of purely tearing down `${CHROOTDIR}/dev` today, but might involve additional steps, as needed for custom functions. This allows end-users to override the various chroot functions without having to modify code in main() or replicate the unmount procedure in an equivalent routine setup via the trap builtin. This change modifies the /dev unmount process to use `umount -f` instead of `umount`. The latter can result in failures if resources are still mounted or are running post-build, whereas the former will clean up any resources still in use by processes running in the chroot at time of build. Moreover, the `chroot_cleanup` routine is now called when the script is killed with `SIGINT` and `SIGTERM`, as well as at `EXIT`, better ensuring that the script's resources are cleaned up in relatively common scenarios that can be detected/handled. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55450 (as part of a larger change) (cherry picked from commit 60baee1fa4848ac969522e03d2c6f273f334edb7) --- release/release.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/release/release.sh b/release/release.sh index 5a6de297f7a1..1f366e287adc 100755 --- a/release/release.sh +++ b/release/release.sh @@ -44,6 +44,14 @@ load_chroot_env() { } load_target_env() { } buildenv_setup() { } +# chroot_cleanup(): Clean up resources setup in chroot_setup() at exit. +# +# This function can be built upon. `_chroot_cleanup` must be added to the end of +# the override function, if overridden. +chroot_cleanup() { + _chroot_cleanup +} # chroot_cleanup() + usage() { echo "Usage: $0 [-c release.conf]" exit 1 @@ -424,6 +432,18 @@ chroot_arm_build_release() { return 0 } # chroot_arm_build_release() +# chroot_cleanup(): Clean up resources setup in chroot_setup() at exit. +# +# This contains steps which must be executed at exit. +# +# Do not override this function: override `chroot_cleanup instead. +_chroot_cleanup() { + if [ -c "${CHROOTDIR}/dev/null" ]; then + echo "Unmounting /dev in ${CHROOTDIR}" + umount -f "${CHROOTDIR}/dev" + fi +} + # main(): Start here. main() { set -e # Everything must succeed @@ -448,7 +468,7 @@ main() { fi fi env_check - trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit + trap chroot_cleanup INT EXIT TERM chroot_setup extra_chroot_setup chroot_build_targethome | help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69ecea3f.448b4.579a1ad>
