public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] isar-image-base: fix some dangling mounts
@ 2017-11-13 12:22 Christian Storm
  2017-11-13 12:50 ` Alexander Smirnov
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Christian Storm @ 2017-11-13 12:22 UTC (permalink / raw)
  To: isar-users; +Cc: Christian Storm

As bitbake/lib/bb/build.py's shell_trap_code() injects
`set -e` into scripts, the premature end of scripts leaves
dangling mounts around. Fix these dangling mounts by hooking
into the EXIT trap handler also setup by shell_trap_code().

Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 meta-isar/recipes-core/images/isar-image-base.bb | 10 ++++++++--
 meta/classes/dpkg-base.bbclass                   | 10 ++++++++--
 meta/classes/ext4-img.bbclass                    | 10 ++++++++--
 meta/recipes-devtools/buildchroot/buildchroot.bb | 10 ++++++++--
 4 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/meta-isar/recipes-core/images/isar-image-base.bb b/meta-isar/recipes-core/images/isar-image-base.bb
index 42aaea3..c2150b1 100644
--- a/meta-isar/recipes-core/images/isar-image-base.bb
+++ b/meta-isar/recipes-core/images/isar-image-base.bb
@@ -52,8 +52,14 @@ do_rootfs() {
         -e 's|##ISAR_DISTRO_SUITE##|${DEBDISTRONAME}|g' \
            "${WORKDIR}/multistrap.conf.in" > "${WORKDIR}/multistrap.conf"
 
-    install -d -m 555 ${IMAGE_ROOTFS}/proc
+    [ ! -d ${IMAGE_ROOTFS}/proc ] && install -d -m 555 ${IMAGE_ROOTFS}/proc
     sudo mount -t proc none ${IMAGE_ROOTFS}/proc
+    _do_rootfs_cleanup() {
+        ret=$?
+        sudo umount ${IMAGE_ROOTFS}/proc 2>/dev/null || true
+        (exit $ret) || bb_exit_handler
+    }
+    trap '_do_rootfs_cleanup' EXIT
 
     # Create root filesystem
     sudo multistrap -a ${DISTRO_ARCH} -d "${IMAGE_ROOTFS}" -f "${WORKDIR}/multistrap.conf"
@@ -62,7 +68,7 @@ do_rootfs() {
     sudo chroot ${IMAGE_ROOTFS} /${DISTRO_CONFIG_SCRIPT} ${MACHINE_SERIAL} ${BAUDRATE_TTY} \
         ${ROOTFS_DEV}
     sudo rm "${IMAGE_ROOTFS}/${DISTRO_CONFIG_SCRIPT}"
-    sudo umount ${IMAGE_ROOTFS}/proc
+    _do_rootfs_cleanup
 }
 
 addtask rootfs before do_build after do_populate
diff --git a/meta/classes/dpkg-base.bbclass b/meta/classes/dpkg-base.bbclass
index 9ded3ae..35af6d5 100644
--- a/meta/classes/dpkg-base.bbclass
+++ b/meta/classes/dpkg-base.bbclass
@@ -21,9 +21,15 @@ dpkg_runbuild() {
 do_build() {
     mkdir -p ${BUILDROOT}
     sudo mount --bind ${WORKDIR} ${BUILDROOT}
+    _do_build_cleanup() {
+        ret=$?
+        sudo umount ${BUILDROOT} 2>/dev/null || true
+        sudo rmdir ${BUILDROOT} 2>/dev/null || true
+        (exit $ret) || bb_exit_handler
+    }
+    trap '_do_build_cleanup' EXIT
     dpkg_runbuild
-    sudo umount ${BUILDROOT}
-    rm -rf ${BUILDROOT}
+    _do_build_cleanup
 }
 
 # Install package to dedicated deploy directory
diff --git a/meta/classes/ext4-img.bbclass b/meta/classes/ext4-img.bbclass
index 18a74ca..83cb137 100644
--- a/meta/classes/ext4-img.bbclass
+++ b/meta/classes/ext4-img.bbclass
@@ -19,9 +19,15 @@ do_ext4_image() {
 
     mkdir -p ${WORKDIR}/mnt
     sudo mount -o loop ${EXT4_IMAGE_FILE} ${WORKDIR}/mnt
+    _do_ext4_image_cleanup() {
+        ret=$?
+        sudo umount ${WORKDIR}/mnt 2>/dev/null || true
+        sudo rmdir ${WORKDIR}/mnt 2>/dev/null || true
+        (exit $ret) || bb_exit_handler
+    }
+    trap '_do_ext4_image_cleanup' EXIT
     sudo cp -r ${IMAGE_ROOTFS}/* ${WORKDIR}/mnt
-    sudo umount ${WORKDIR}/mnt
-    rm -r ${WORKDIR}/mnt
+    _do_ext4_image_cleanup
 }
 
 addtask ext4_image before do_build after do_copy_boot_files
diff --git a/meta/recipes-devtools/buildchroot/buildchroot.bb b/meta/recipes-devtools/buildchroot/buildchroot.bb
index ace64ba..4cae9fc 100644
--- a/meta/recipes-devtools/buildchroot/buildchroot.bb
+++ b/meta/recipes-devtools/buildchroot/buildchroot.bb
@@ -52,8 +52,14 @@ do_build() {
         -e 's|##DIR_HOOKS##|./'"$WORKDIR_REL"'/hooks_multistrap|g' \
            "${WORKDIR}/multistrap.conf.in" > "${WORKDIR}/multistrap.conf"
 
-    install -d -m 555 ${BUILDCHROOT_DIR}/proc
+    [ ! -d ${BUILDCHROOT_DIR}/proc ] && install -d -m 555 ${BUILDCHROOT_DIR}/proc
     sudo mount -t proc none ${BUILDCHROOT_DIR}/proc
+    _do_build_cleanup() {
+        ret=$?
+        sudo umount ${BUILDCHROOT_DIR}/proc 2>/dev/null || true
+        (exit $ret) || bb_exit_handler
+    }
+    trap '_do_build_cleanup' EXIT    
 
     # Create root filesystem
     sudo multistrap -a ${DISTRO_ARCH} -d "${BUILDCHROOT_DIR}" -f "${WORKDIR}/multistrap.conf"
@@ -63,5 +69,5 @@ do_build() {
 
     # Configure root filesystem
     sudo chroot ${BUILDCHROOT_DIR} /configscript.sh
-    sudo umount ${BUILDCHROOT_DIR}/proc
+    _do_build_cleanup
 }
-- 
2.15.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-11-14 16:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 12:22 [PATCH] isar-image-base: fix some dangling mounts Christian Storm
2017-11-13 12:50 ` Alexander Smirnov
2017-11-13 12:57   ` Christian Storm
2017-11-13 13:53 ` Alexander Smirnov
2017-11-13 14:24   ` Christian Storm
2017-11-13 14:47     ` Alexander Smirnov
2017-11-14  7:36       ` Christian Storm
2017-11-14  7:48         ` Alexander Smirnov
2017-11-14  8:58           ` Christian Storm
2017-11-13 13:57 ` Henning Schild
2017-11-14 16:01 ` Alexander Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox