From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6487873763254730752 X-Received: by 10.37.43.8 with SMTP id r8mr8685471ybr.52.1510581209497; Mon, 13 Nov 2017 05:53:29 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.129.48.209 with SMTP id w200ls371455yww.31.gmail; Mon, 13 Nov 2017 05:53:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMa37JVoqt5k08FXMUQqznEfvTOBqS2vBKSRTJzVBhA4fFPjiEJodIFdU3Y8dTrddPOdDJZm X-Received: by 10.129.181.16 with SMTP id t16mr1864340ywh.197.1510581209088; Mon, 13 Nov 2017 05:53:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510581209; cv=none; d=google.com; s=arc-20160816; b=JVdoJ4b9NwNzvZDbIyXiVVSNxWP3U/F4JtwUiKpb5tkDetVz8FZOeiTtiSrQBERBYD TgroECsaashPveJ3aBtBuUibDT6RTGNs9haO24Erzyn4u7lDiG+Okk/vKRG07wYig22c e1YP168jAlIkPamEzdWTndO8nvRIu5R7baxyxYR76ytzO7ry/1MPknzVCXTkYOy9Z8lK l35ks3WHb8wROeDg4vrraZBI0Aa2mTAwob/2eZv5XZBjgELi6Bg5AMSN5u6dU3T58V2U Bt/UAb1//za4ovr4iOSGzVKPnmUx9AxRC8eL8AahAZMoQC6sCSgR3hi5U68euOkLhQze 0KuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:to:subject :arc-authentication-results; bh=CObVlFxzj0wgP6+grPg3O6b6rVFwvwEHfyzkT6qDQwc=; b=rVJIEufmmtbDajrjg9jzi27xdYABIGyhxaXxzw7iJnqlsz/sVVrr3Hoam1OtfAVOYc mEU8BmaurZ0+vEdWUX3o/BZoAGF3yZ0+Hjppy1117M2Tz7XCSUaPcHiXiABKtoTF0H29 LSxENg6W9mHzzqsM4yHhqgJxJ90eJHCCBu56Fob+0rQPiAjT9UXsShqUvBMfbL8Y9Rq5 b3iA2YlmAaFaCkvMRbBUo4jM3Raawxo1VL1hxoWEAYhDnLkQbZAvPxDPwIyTgEXq7JT1 tyNF6zxDaa9nb7/oke6t1zUeGa/YKnLbhbD7RL6iRYD0U/PB+ZRzeQ/YuNWbJVSIbSQR aV2w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: best guess record for domain of asmirnov@ilbers.de designates 85.214.62.211 as permitted sender) smtp.mailfrom=asmirnov@ilbers.de Return-Path: Received: from aqmola.ilbers.de (aqmola.ilbers.de. [85.214.62.211]) by gmr-mx.google.com with ESMTPS id n78si461017ywn.1.2017.11.13.05.53.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Nov 2017 05:53:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of asmirnov@ilbers.de designates 85.214.62.211 as permitted sender) client-ip=85.214.62.211; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: best guess record for domain of asmirnov@ilbers.de designates 85.214.62.211 as permitted sender) smtp.mailfrom=asmirnov@ilbers.de Received: from [10.0.2.15] ([188.227.110.165]) (authenticated bits=0) by aqmola.ilbers.de (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id vADDrNfM005533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Mon, 13 Nov 2017 14:53:25 +0100 Subject: Re: [PATCH] isar-image-base: fix some dangling mounts To: Christian Storm , isar-users@googlegroups.com References: <20171113122239.19792-1-christian.storm@siemens.com> From: Alexander Smirnov Message-ID: <875ca5fe-4116-ac26-bef6-20b6225aa809@ilbers.de> Date: Mon, 13 Nov 2017 16:53:18 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171113122239.19792-1-christian.storm@siemens.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: 9aUUOQaoNWYq Hi, On 11/13/2017 03:22 PM, Christian Storm wrote: > 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(). > Thank you for the explanation (in another main), now I've got the idea! > Signed-off-by: Christian Storm > --- > 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 > } > Here I see that you insert quite similar patterns across the Isar code, would it be better to have one global clean up function like? do_isar_mount_cleanup () { if [ -d "${WORKDIR}/mnt" ]; then # umount and remove fi if [ -d "${WORKDIR}/rootfs/proc" ]; then # umount and remove fi if [ -d "${BUILDCHROOT_DIR}/proc" ]; then # umount and remove fi etc... } This approach will significantly simplify maintenance of clean up traps and adding of new possible mounts to Isar. What do you think? Alex