public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] meta: refactored flock usage
@ 2019-02-14 12:18 claudius.heine.ext
  2019-02-14 12:50 ` Claudius Heine
  2019-02-14 16:08 ` [PATCH v2] " claudius.heine.ext
  0 siblings, 2 replies; 12+ messages in thread
From: claudius.heine.ext @ 2019-02-14 12:18 UTC (permalink / raw)
  To: isar-users; +Cc: Claudius Heine

From: Claudius Heine <ch@denx.de>

Currently much care has to be taken in order to correctly escape strings
inside flock commands. And there is also on instance where this was
incorrectly used (isar-bootstrap.inc).

The usage of flock was changed to no longer require single or double
ticks. Instead commands are run inside a subshell.

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/buildchroot.bbclass                    | 6 ++++--
 meta/classes/wic-img.bbclass                        | 6 ++++--
 meta/recipes-core/isar-bootstrap/isar-bootstrap.inc | 7 +++++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/meta/classes/buildchroot.bbclass b/meta/classes/buildchroot.bbclass
index 0d4ff4e..0ee6ca9 100644
--- a/meta/classes/buildchroot.bbclass
+++ b/meta/classes/buildchroot.bbclass
@@ -22,7 +22,8 @@ python __anonymous() {
 MOUNT_LOCKFILE = "${BUILDCHROOT_DIR}/mount.lock"
 
 buildchroot_do_mounts() {
-    sudo flock ${MOUNT_LOCKFILE} -c ' \
+    sudo -s <<EOSUDO
+        ( flock 9
         set -e
         if ! grep -q ${BUILDCHROOT_DIR}/isar-apt /proc/mounts; then
             mount --bind ${REPO_ISAR_DIR}/${DISTRO} ${BUILDCHROOT_DIR}/isar-apt
@@ -36,5 +37,6 @@ buildchroot_do_mounts() {
 
         # Refresh /etc/resolv.conf at this chance
         cp -L /etc/resolv.conf ${BUILDCHROOT_DIR}/etc
-        '
+        ) 9>${MOUNT_LOCKFILE}
+EOSUDO
 }
diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass
index 76602d8..febc5dc 100644
--- a/meta/classes/wic-img.bbclass
+++ b/meta/classes/wic-img.bbclass
@@ -87,14 +87,16 @@ do_build[stamp-extra-info] = "${DISTRO}-${DISTRO_ARCH}"
 
 do_wic_image() {
     buildchroot_do_mounts
-    sudo flock ${MOUNT_LOCKFILE} -c ' \
+    sudo -s <<EOSUDO
+        ( flock 9
         for dir in ${BBLAYERS} ${STAGING_DIR} ${ISARROOT}/scripts; do
             mkdir -p ${BUILDCHROOT_DIR}/$dir
             if ! mountpoint ${BUILDCHROOT_DIR}/$dir >/dev/null 2>&1; then
                 mount --bind --make-private $dir ${BUILDCHROOT_DIR}/$dir
             fi
         done
-        '
+        ) 9>${MOUNT_LOCKFILE}
+EOSUDO
     export FAKEROOTCMD=${FAKEROOTCMD}
     export BUILDDIR=${BUILDDIR}
     export MTOOLS_SKIP_CHECK=1
diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index 234d339..b385825 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -214,7 +214,8 @@ isar_bootstrap() {
         fi
     fi
     E="${@bb.utils.export_proxies(d)}"
-    sudo -E flock "${ISAR_BOOTSTRAP_LOCK}" -c "\
+    sudo -E -s <<EOSUDO
+        ( flock 9
         set -e
         if [ ! -e "${DEPLOY_ISAR_BOOTSTRAP}" ]; then
             rm -rf "${ROOTFSDIR}"
@@ -295,7 +296,9 @@ isar_bootstrap() {
 
             # Finalize debootstrap by setting the link in deploy
             ln -Tfsr "${ROOTFSDIR}" "${DEPLOY_ISAR_BOOTSTRAP}"
-        fi"
+        fi
+        ) 9>'${ISAR_BOOTSTRAP_LOCK}'
+EOSUDO
 }
 
 CLEANFUNCS = "clean_deploy"
-- 
2.20.1


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

end of thread, other threads:[~2019-03-12 13:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-14 12:18 [PATCH] meta: refactored flock usage claudius.heine.ext
2019-02-14 12:50 ` Claudius Heine
2019-02-14 16:08 ` [PATCH v2] " claudius.heine.ext
2019-03-07 13:23   ` Claudius Heine
2019-03-08 17:38     ` Baurzhan Ismagulov
2019-03-09 19:11       ` Claudius Heine
2019-03-12 10:16       ` Andreas Reichel
2019-03-08 17:49   ` Jan Kiszka
2019-03-09 19:08     ` Claudius Heine
2019-03-12 10:20       ` Jan Kiszka
2019-03-12 10:22         ` Claudius Heine
2019-03-12 13:18   ` Maxim Yu. Osipov

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