From 29502a3e3b16d84ce8ef29aa41b16d34d22a8ea3 Mon Sep 17 00:00:00 2001 From: classabbyamp Date: Tue, 16 Jan 2024 11:59:13 -0500 Subject: [PATCH] mklive.sh: fix issues with error handling and unmounting pseudofs - add some error handling to `umount_pseudofs` - disable the trap before running `error_out` to stop it running multiple times - add `--one-file-system` to ensure that the `rm -rf` can't screw you fixes #364 --- mklive.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/mklive.sh b/mklive.sh index a1d4a5c70b..fb54cb949d 100755 --- a/mklive.sh +++ b/mklive.sh @@ -52,14 +52,18 @@ mount_pseudofs() { done } umount_pseudofs() { - umount -R -f "$ROOTFS"/sys >/dev/null 2>&1 - umount -R -f "$ROOTFS"/dev >/dev/null 2>&1 - umount -R -f "$ROOTFS"/proc >/dev/null 2>&1 + for f in sys dev proc; do + if ! umount -R -f "$ROOTFS/$f"; then + info_msg "ERROR: failed to unmount $ROOTFS/$f/" + return 1 + fi + done } error_out() { - umount_pseudofs - [ -d "$BUILDDIR" -a -z "$KEEP_BUILDDIR" ] && rm -rf "$BUILDDIR" - exit "${1:=0}" + trap - INT TERM 0 + umount_pseudofs || exit "${1:-0}" + [ -d "$BUILDDIR" -a -z "$KEEP_BUILDDIR" ] && rm -rf --one-file-system "$BUILDDIR" + exit "${1:-0}" } usage() {