Skip to content

Commit 60baee1

Browse files
committed
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)
1 parent b24fc79 commit 60baee1

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

release/release.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ load_target_env() { }
5353
# buildenv_setup(): set up the build environment needed for post-chroot_setup()
5454
buildenv_setup() { }
5555

56+
# chroot_cleanup(): Clean up resources setup in chroot_setup() at exit.
57+
#
58+
# This function can be built upon. `_chroot_cleanup` must be added to the end of
59+
# the override function, if overridden.
60+
chroot_cleanup() {
61+
_chroot_cleanup
62+
} # chroot_cleanup()
63+
5664
usage() {
5765
echo "Usage: $0 [-c release.conf]"
5866
exit 1
@@ -436,6 +444,18 @@ chroot_arm_build_release() {
436444
return 0
437445
} # chroot_arm_build_release()
438446

447+
# chroot_cleanup(): Clean up resources setup in chroot_setup() at exit.
448+
#
449+
# This contains steps which must be executed at exit.
450+
#
451+
# Do not override this function: override `chroot_cleanup instead.
452+
_chroot_cleanup() {
453+
if [ -c "${CHROOTDIR}/dev/null" ]; then
454+
echo "Unmounting /dev in ${CHROOTDIR}"
455+
umount -f "${CHROOTDIR}/dev"
456+
fi
457+
}
458+
439459
# main(): Start here.
440460
main() {
441461
set -e # Everything must succeed
@@ -460,7 +480,7 @@ main() {
460480
fi
461481
fi
462482
env_check
463-
trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
483+
trap chroot_cleanup INT EXIT TERM
464484
chroot_setup
465485
extra_chroot_setup
466486
chroot_build_target

0 commit comments

Comments
 (0)