Abort the payload generation on extract_image errors.
extract_image, in particular extract_image_brillo, spawns multiple
processes to handle the unzipping and unsparsing works in parallel.
However, `wait` doesn't abort the execution on child process errors.
This CL tracks the PIDs of the worker processes. It then waits for each
individual PID and aborts appropriately. No-op for the CrOS path.
Bug: 129773355
Test: Inject error into simg2img. brillo_update_payload aborts.
Change-Id: Id87aa5216fee7e9db132b7f7947742d2ac11b2bc
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index c88709c..f535185 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -248,6 +248,9 @@
# List of partition names in order.
declare -a PARTITIONS_ORDER
+# A list of PIDs of the extract_image workers.
+EXTRACT_IMAGE_PIDS=()
+
# A list of temporary files to remove during cleanup.
CLEANUP_FILES=()
@@ -530,6 +533,7 @@
# Extract partitions in background.
extract_partition_brillo "${image}" "${partitions_array}" "${part}" \
"${part_file}" "${part_map_file}" &
+ EXTRACT_IMAGE_PIDS+=("$!")
eval "${partitions_array}[\"${part}\"]=\"${part_file}\""
eval "${partitions_array}_MAP[\"${part}\"]=\"${part_map_file}\""
done
@@ -559,8 +563,12 @@
extract_image "${FLAGS_source_image}" SRC_PARTITIONS
fi
extract_image "${FLAGS_target_image}" DST_PARTITIONS PARTITIONS_ORDER
- # Wait for all subprocesses.
- wait
+ # Wait for all subprocesses to finish. Not using `wait` since it doesn't die
+ # on non-zero subprocess exit code. Not using `wait ${EXTRACT_IMAGE_PIDS[@]}`
+ # as it gives the status of the last process it has waited for.
+ for pid in ${EXTRACT_IMAGE_PIDS[@]}; do
+ wait ${pid}
+ done
cleanup_partition_array SRC_PARTITIONS
cleanup_partition_array SRC_PARTITIONS_MAP
cleanup_partition_array DST_PARTITIONS