Skip to content

Commit

Permalink
mklive.sh: fix issues with error handling and unmounting pseudofs
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
classabbyamp committed Jan 16, 2024
1 parent 0783160 commit 29502a3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions mklive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 29502a3

Please sign in to comment.