Skip to content

Commit 44a30c4

Browse files
committed
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
1 parent 498083d commit 44a30c4

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

mklive.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2525
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626
#-
27-
trap 'error_out $? $LINENO' INT TERM 0
2827
umask 022
2928

3029
. ./lib.sh
@@ -52,14 +51,18 @@ mount_pseudofs() {
5251
done
5352
}
5453
umount_pseudofs() {
55-
umount -R -f "$ROOTFS"/sys >/dev/null 2>&1
56-
umount -R -f "$ROOTFS"/dev >/dev/null 2>&1
57-
umount -R -f "$ROOTFS"/proc >/dev/null 2>&1
54+
for f in sys dev proc; do
55+
if ! umount -R -f "$ROOTFS/$f"; then
56+
info_msg "ERROR: failed to unmount $ROOTFS/$f/"
57+
return 1
58+
fi
59+
done
5860
}
5961
error_out() {
60-
umount_pseudofs
61-
[ -d "$BUILDDIR" -a -z "$KEEP_BUILDDIR" ] && rm -rf "$BUILDDIR"
62-
exit "${1:=0}"
62+
trap - INT TERM 0
63+
umount_pseudofs || exit "${1:-0}"
64+
[ -d "$BUILDDIR" ] && [ -z "$KEEP_BUILDDIR" ] && rm -rf --one-file-system "$BUILDDIR"
65+
exit "${1:-0}"
6366
}
6467

6568
usage() {
@@ -271,7 +274,7 @@ generate_grub_efi_boot() {
271274
}
272275

273276
generate_squashfs() {
274-
umount_pseudofs
277+
umount_pseudofs || exit 1
275278

276279
# Find out required size for the rootfs and create an ext3fs image off it.
277280
ROOTFS_SIZE=$(du --apparent-size -sm "$ROOTFS"|awk '{print $1}')
@@ -366,6 +369,8 @@ if [ "$(id -u)" -ne 0 ]; then
366369
die "Must be run as root, exiting..."
367370
fi
368371

372+
trap 'error_out $? $LINENO' INT TERM 0
373+
369374
if [ -n "$ROOTDIR" ]; then
370375
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d)
371376
else

0 commit comments

Comments
 (0)