[2/3] deploy-image: report the result of the console holding the lock

Message ID 20261027110601.1197504-2-srinuvasan.a@siemens.com
State Under Review
Headers show
Series [1/3] installer: add reusable progress gauge | expand

Commit Message

srinuvasan.a Oct. 27, 2026, 11:06 a.m. UTC
From: Srinuvasan A <srinuvasan.a@siemens.com>

When several installer consoles run, only the one holding the
installation lock copies the image. Consoles that do not get the lock
waited for it to finish and then always reported success, even if the
installation had failed.

Wait for the lock holder with flock and let it record its outcome in
/run/installer.result. Consoles that waited return success only if the
holder succeeded.

Signed-off-by: Srinuvasan A <srinuvasan.a@siemens.com>
Suggested-by: Cedric Hombourger <cedric.hombourger@siemens.com>
---
 .../deploy-image/files/usr/bin/sys_api.sh     | 27 +++++++++----------
 1 file changed, 12 insertions(+), 15 deletions(-)

Patch

diff --git a/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh b/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh
index 5f591745..26b39108 100644
--- a/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh
+++ b/meta-isar/recipes-installer/deploy-image/files/usr/bin/sys_api.sh
@@ -278,7 +278,9 @@  sys_bmap_options_for_image() {
 #
 # Performs the actual bmaptool copy, serializing concurrent installer
 # consoles via flock. When UI hook functions are available, this API
-# uses them to present a progress gauge in attended mode.
+# uses them to present a progress gauge in attended mode. Consoles that
+# do not get the lock wait for its holder and report its result, which is
+# kept in /run/installer.result.
 #
 # Optional UI hooks (if defined):
 #   ui_start_progress_gauge <pipe_path>
@@ -289,6 +291,7 @@  sys_install_image_with_lock() {
     local target_device="$2"
     local lockfile="/run/installer.lock"
     local progress_pipe="/run/installer.fifo"
+    local result_file="/run/installer.result"
     local bmap_options
     local bmap_version
     local quiet_flag=""
@@ -297,6 +300,7 @@  sys_install_image_with_lock() {
 
     exec 9>"$lockfile"
     if flock -n 9; then
+        rm -f "$result_file"
         bmap_version=$(bmaptool --version | awk '{ print $NF }')
 
         if sys_version_ge "$bmap_version" "3.6"; then
@@ -323,27 +327,20 @@  sys_install_image_with_lock() {
             if declare -F ui_stop_progress_gauge >/dev/null; then
                 ui_stop_progress_gauge
             fi
+            echo failed > "$result_file"
             return 1
         fi
 
         if declare -F ui_stop_progress_gauge >/dev/null; then
             ui_stop_progress_gauge
         fi
-    else
-        echo "Installation already running in another console."
-        sleep 5
 
-        if [ -e "$progress_pipe" ]; then
-            echo "Installation progress..."
-            tail -f "$progress_pipe" | while read -r line; do
-                printf "\r%s%%" "$line"
-            done
-        else
-            echo "Waiting for installation to finish..."
-            while pgrep -x "bmaptool" >/dev/null; do
-                sleep 5
-            done
-        fi
+        echo ok > "$result_file"
+    else
+        echo "Installation already running in another console. Waiting for it to finish..."
+        flock 9
+        # The other console owns the result; only report success if it did.
+        [ "$(cat "$result_file" 2>/dev/null)" = ok ] || return 1
     fi
 
     return 0