installer: fix race condition with multiple consoles running unattended

Message ID 20260218124506.399124-1-badrikesh.prusty@siemens.com
State Under Review
Headers show
Series installer: fix race condition with multiple consoles running unattended | expand

Commit Message

Prusty, Badrikesh Feb. 18, 2026, 12:45 p.m. UTC
* Add lockfile `/tmp/installer.lock` to prevent simultaneous unattended
  installs across multiple consoles.
* Add progress monitoring for installations started in another console
  via progress pipe.
* Periodically check if bmaptool is still running when progress pipe is
  unavailable and continue once bmaptool completes.

This resolves the race condition between consoles and prevents issues
with long-running or partially completed installations.

Signed-off-by: Badrikesh Prusty <badrikesh.prusty@siemens.com>
---
 .../files/usr/bin/deploy-image-wic.sh         | 41 +++++++++++++++----
 1 file changed, 32 insertions(+), 9 deletions(-)

Patch

diff --git a/meta-isar/recipes-installer/deploy-image/files/usr/bin/deploy-image-wic.sh b/meta-isar/recipes-installer/deploy-image/files/usr/bin/deploy-image-wic.sh
index 9c041a50..0097a4b4 100755
--- a/meta-isar/recipes-installer/deploy-image/files/usr/bin/deploy-image-wic.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/usr/bin/deploy-image-wic.sh
@@ -231,7 +231,11 @@  version_ge() {
     fi
 }
 
-if ! $installer_unattended; then
+lockfile="/tmp/installer.lock"
+progress_pipe="/tmp/progress"
+
+exec 9>"$lockfile"
+if flock -n 9; then
     # Get bmap-tools version
     bmap_version=$(bmaptool --version | awk '{ print $NF }')
 
@@ -259,16 +263,35 @@  if ! $installer_unattended; then
 
         gauge_pid=$!
     fi
-fi
 
-if ! bmaptool $quiet_flag copy $bmap_options "$installer_image_uri" "$installer_target_dev"; then
-    kill "$gauge_pid"
-    exit 1
-fi
+    if ! bmaptool $quiet_flag copy $bmap_options "$installer_image_uri" "$installer_target_dev"; then
+        kill "$gauge_pid"
+        exit 1
+    fi
+
+    # Attempt to terminate the gauge process if still running.
+    # Errors are ignored since the process may already have exited.
+    kill "$gauge_pid" 2>/dev/null
+else
+    echo "Installation already running in another console."
+
+    # Wait for running console to create the progress pipe
+    sleep 2
 
-# Attempt to terminate the gauge process if still running.
-# Errors are ignored since the process may already have exited.
-kill "$gauge_pid" 2>/dev/null
+    # Check if progress pipe exists and has content
+    if [ -e "$progress_pipe" ]; then
+        echo "Installation progress..."
+        tail -f "$progress_pipe" | while read line; do
+            printf "\r%s%%" "$line"
+        done
+    else
+        # Periodically check if bmaptool is still running every 5 seconds
+        echo "Waiting for installation to finish..."
+        while pgrep -x "bmaptool" > /dev/null; do
+            sleep 5
+        done
+    fi
+fi
 
 if ! $installer_unattended; then
     dialog --title "Reboot" \