initramfs: Avoid hanging mounts on failed update-initramfs

Message ID 20241017075749.101476-1-amikan@ilbers.de
State Accepted, archived
Headers show
Series initramfs: Avoid hanging mounts on failed update-initramfs | expand

Commit Message

Anton Mikanovich Oct. 17, 2024, 7:57 a.m. UTC
If update-initramfs fails during do_generate_initramfs task execution
there will be mounts left behind.
Protect it with a trap for cleanup in case of failure.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/initramfs.bbclass | 4 ++++
 1 file changed, 4 insertions(+)

Patch

diff --git a/meta/classes/initramfs.bbclass b/meta/classes/initramfs.bbclass
index 42013356..0197a60b 100644
--- a/meta/classes/initramfs.bbclass
+++ b/meta/classes/initramfs.bbclass
@@ -35,6 +35,10 @@  do_generate_initramfs[sstate-inputdirs] = "${DEPLOYDIR}"
 do_generate_initramfs[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
 do_generate_initramfs() {
     rootfs_do_mounts
+
+    trap 'exit 1' INT HUP QUIT TERM ALRM USR1
+    trap 'rootfs_do_umounts' EXIT
+
     rootfs_do_qemu
 
     sudo -E chroot "${INITRAMFS_ROOTFS}" sh -c '\