git: 60baee1fa484 - main - release.sh: add chroot cleanup routine
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 22 Mar 2026 03:02:19 UTC
The branch main has been updated by ngie:
URL: https://cgit.FreeBSD.org/src/commit/?id=60baee1fa4848ac969522e03d2c6f273f334edb7
commit 60baee1fa4848ac969522e03d2c6f273f334edb7
Author: Enji Cooper <ngie@FreeBSD.org>
AuthorDate: 2026-03-22 02:57:25 +0000
Commit: Enji Cooper <ngie@FreeBSD.org>
CommitDate: 2026-03-22 03:02:09 +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)
---
release/release.sh | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/release/release.sh b/release/release.sh
index be3a0785d945..48c505470524 100755
--- a/release/release.sh
+++ b/release/release.sh
@@ -53,6 +53,14 @@ load_target_env() { }
# buildenv_setup(): set up the build environment needed for post-chroot_setup()
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
@@ -436,6 +444,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
@@ -460,7 +480,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_target