public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v1 2/5] mount: Allow calling unmount on not mounted paths
Date: Wed,  7 Jul 2021 19:38:48 +0300	[thread overview]
Message-ID: <20210707163851.204296-3-amikan@ilbers.de> (raw)
In-Reply-To: <20210707163851.204296-1-amikan@ilbers.de>

Make buildchroot_undo_mounts and rootfs_undo_mounts functions do not
fail if calling without buildchroot_do_mounts and rootfs_do_mounts.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/buildchroot.bbclass | 20 ++++++++++----------
 meta/classes/rootfs.bbclass      | 20 ++++++++++----------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/meta/classes/buildchroot.bbclass b/meta/classes/buildchroot.bbclass
index 806a29f..9c27711 100644
--- a/meta/classes/buildchroot.bbclass
+++ b/meta/classes/buildchroot.bbclass
@@ -23,16 +23,18 @@ python __anonymous() {
 
 MOUNT_LOCKFILE = "${BUILDCHROOT_DIR}.lock"
 
+BUILDCHROOT_MOUNT_CNT = "${BUILDCHROOT_DIR}.mount"
+
 buildchroot_do_mounts() {
     sudo -s <<'EOSUDO'
         ( flock 9
         set -e
 
         count="1"
-        if [ -f '${BUILDCHROOT_DIR}.mount' ]; then
-            count=$(($(cat '${BUILDCHROOT_DIR}.mount') + 1))
+        if [ -f "${BUILDCHROOT_MOUNT_CNT}" ]; then
+            count=$(($(cat "${BUILDCHROOT_MOUNT_CNT}") + 1))
         fi
-        echo $count > '${BUILDCHROOT_DIR}.mount'
+        echo $count > "${BUILDCHROOT_MOUNT_CNT}"
         if [ $count -gt 1 ]; then
             exit 0
         fi
@@ -77,17 +79,15 @@ buildchroot_undo_mounts() {
         ( flock 9
         set -e
 
-        if [ -f '${BUILDCHROOT_DIR}.mount' ]; then
-            count=$(($(cat '${BUILDCHROOT_DIR}.mount') - 1))
-            echo $count > '${BUILDCHROOT_DIR}.mount'
-        else
-            echo "Could not find mount counter"
-            exit 1
+        count="0"
+        if [ -f "${BUILDCHROOT_MOUNT_CNT}" ]; then
+            count=$(($(cat "${BUILDCHROOT_MOUNT_CNT}") - 1))
+            echo $count > "${BUILDCHROOT_MOUNT_CNT}"
         fi
         if [ $count -gt 0 ]; then
             exit 0
         fi
-        rm ${BUILDCHROOT_DIR}.mount
+        rm -f "${BUILDCHROOT_MOUNT_CNT}"
 
         mountpoint -q '${BUILDCHROOT_DIR}/base-apt' && \
             umount ${BUILDCHROOT_DIR}/base-apt && \
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 50d6408..9ccc8e3 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -28,6 +28,8 @@ export LC_ALL = "C"
 
 MOUNT_LOCKFILE = "${ROOTFSDIR}.lock"
 
+ROOTFS_MOUNT_CNT = "${ROOTFSDIR}.mount"
+
 rootfs_do_mounts[weight] = "3"
 rootfs_do_mounts() {
     sudo -s <<'EOSUDO'
@@ -35,10 +37,10 @@ rootfs_do_mounts() {
         set -e
 
         count="1"
-        if [ -f '${ROOTFSDIR}.mount' ]; then
-            count=$(($(cat '${ROOTFSDIR}.mount') + 1))
+        if [ -f "${ROOTFS_MOUNT_CNT}" ]; then
+            count=$(($(cat "${ROOTFS_MOUNT_CNT}") + 1))
         fi
-        echo $count > '${ROOTFSDIR}.mount'
+        echo $count > "${ROOTFS_MOUNT_CNT}"
         if [ $count -gt 1 ]; then
             exit 0
         fi
@@ -79,17 +81,15 @@ rootfs_undo_mounts() {
         ( flock 9
         set -e
 
-        if [ -f '${ROOTFSDIR}.mount' ]; then
-            count=$(($(cat '${ROOTFSDIR}.mount') - 1))
-            echo $count > '${ROOTFSDIR}.mount'
-        else
-            echo "Could not find mount counter"
-            exit 1
+        count="0"
+        if [ -f "${ROOTFS_MOUNT_CNT}" ]; then
+            count=$(($(cat "${ROOTFS_MOUNT_CNT}") - 1))
+            echo $count > "${ROOTFS_MOUNT_CNT}"
         fi
         if [ $count -gt 0 ]; then
             exit 0
         fi
-        rm ${ROOTFSDIR}.mount
+        rm -f "${ROOTFS_MOUNT_CNT}"
 
         mountpoint -q '${ROOTFSDIR}/base-apt' && \
             umount ${ROOTFSDIR}/base-apt && \
-- 
2.25.1


  parent reply	other threads:[~2021-07-07 16:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-07 16:38 [PATCH v1 0/5] Restore downstream mounts compatibility Anton Mikanovich
2021-07-07 16:38 ` [PATCH v1 1/5] Revert "dpkg: Make mount buildroot reliable" Anton Mikanovich
2021-07-08 12:16   ` Jan Kiszka
2021-07-07 16:38 ` Anton Mikanovich [this message]
2021-07-08 12:17   ` [PATCH v1 2/5] mount: Allow calling unmount on not mounted paths Jan Kiszka
2021-07-07 16:38 ` [PATCH v1 3/5] dpkg: Remove unmount loop Anton Mikanovich
2021-07-08 12:21   ` Jan Kiszka
2021-07-08 14:35     ` Anton Mikanovich
2021-07-08 16:16       ` Jan Kiszka
2021-08-17 13:02     ` Anton Mikanovich
2021-07-07 16:38 ` [PATCH v1 4/5] image: Add reference counter Anton Mikanovich
2021-07-07 16:38 ` [PATCH v1 5/5] events: Unmount all lost mounts at task fail Anton Mikanovich
2021-07-08 12:24   ` Jan Kiszka
2021-07-08 14:41     ` Anton Mikanovich
2021-07-08 16:28       ` Jan Kiszka
2021-07-12 16:08         ` Baurzhan Ismagulov

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=20210707163851.204296-3-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --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