From 528456407131c8771588fd3d53f91785b728752e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 13 Mar 2019 16:38:49 +1100 Subject: [PATCH] Unmount internal mounts on finalise errors This is only one line, but it takes a lot to untangle ... basically the current "correct" path is: --- mk_build_dir() -> sets trap trap_cleanup EXIT ... stuff .. mount_proc_dev_sys -> mounts $TMP_MOUNT_PATH/ pre-finalise.d finalise.d unmount_image $TMP_BUILD_DIR/mnt # nb == $TMP_MOUNT_PATH -> unmount_dir() -> recursive unmount everything inside TMP_MOUNT_PATH TMP_IMAGE_PATH=$(dib-block-device getval image-path) export TMP_IMAGE_PATH dib-block-device umount dib-block-device cleanup ... actually cleanup directories ... --- Our current failure exit trap does: --- dib-block-device umount unmount_image ... --- Note this is the *opposite* of what is done in the correct exit path. In the failure case, if a script fails in the finalise stages it leads to /proc, /sys, /dev etc. still being mounted inside the image; the "dib-block-device umount" call doesn't know anything about these mounts and tries to unmount the parent directory, and we get a hard failure with a busy mount, and all the mounts are subsequently leaked. Note that "unmount_dir", which is ultimately called by "unmount_image", already knows to skip those mounts that "dib-block-device umount" manages (this is the DIB_MOUNTPOINTS list). This is further evidence it should be called *before* the dib-block-device umount. Change-Id: Ibef3ce9d1167b9c4ff3d5717b113cd3ed374f5e3 --- diskimage_builder/lib/img-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/diskimage_builder/lib/img-functions b/diskimage_builder/lib/img-functions index 908fb20c6..f158ee95d 100644 --- a/diskimage_builder/lib/img-functions +++ b/diskimage_builder/lib/img-functions @@ -39,8 +39,8 @@ function trap_cleanup() { } function cleanup () { - dib-block-device umount unmount_image + dib-block-device umount cleanup_build_dir cleanup_image_dir }