public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Henning Schild <henning.schild@siemens.com>
To: "[ext] Christian Storm" <christian.storm@siemens.com>
Cc: <isar-users@googlegroups.com>
Subject: Re: [PATCH] isar-image-base: fix some dangling mounts
Date: Mon, 13 Nov 2017 14:57:12 +0100	[thread overview]
Message-ID: <20171113145712.1b259253@md1em3qc> (raw)
In-Reply-To: <20171113122239.19792-1-christian.storm@siemens.com>

Cool, i suggested before to use exception handling for that problem,
just did not know how that is done in bb.

Henning

Am Mon, 13 Nov 2017 13:22:39 +0100
schrieb "[ext] Christian Storm" <christian.storm@siemens.com>:

> 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
>  }


  parent reply	other threads:[~2017-11-13 13:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 12:22 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 [this message]
2017-11-14 16:01 ` Alexander Smirnov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171113145712.1b259253@md1em3qc \
    --to=henning.schild@siemens.com \
    --cc=christian.storm@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox