From efe8732e47435187ef7549c4ecc204206508ff12 Mon Sep 17 00:00:00 2001 From: Kroese Date: Mon, 27 Jul 2026 12:03:24 +0200 Subject: [PATCH] fix: Avoid shadowing PID output variables (#1337) --- src/power.sh | 20 ++++---------------- src/utils.sh | 6 ++---- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/power.sh b/src/power.sh index 986329d..25b17fb 100644 --- a/src/power.sh +++ b/src/power.sh @@ -67,18 +67,8 @@ displayReason() { readQemuPid() { - local -n _pid="$1" - local file - local pid - - for file in "$QEMU_START_PID" "$QEMU_PID"; do - if readPidFile pid "$file"; then - _pid="$pid" - return 0 - fi - done - - return 1 + readPidFile "$1" "$QEMU_START_PID" && return 0 + readPidFile "$1" "$QEMU_PID" } qemuPidFile() { @@ -102,16 +92,14 @@ waitQemuExit() { waitQemuPid() { - local -n _pid="$1" - local cnt=0 value + local cnt=0 - while ! readQemuPid value; do + while ! readQemuPid "$1"; do sleep 0.02 cnt=$((cnt + 1)) (( cnt >= 50 )) && return 1 done - _pid="$value" return 0 } diff --git a/src/utils.sh b/src/utils.sh index 9a79033..edfceec 100644 --- a/src/utils.sh +++ b/src/utils.sh @@ -10,13 +10,11 @@ warn () { printf "%b%s%b" "\E[1;31m❯ " "Warning: ${1:-}" "\E[0m\n" >&2; } readPidFile() { local -n _pid="$1" - local file="$2" - _pid="" - [ -s "$file" ] || return 1 + [ -s "$2" ] || return 1 - _pid=$(<"$file") + _pid=$(<"$2") if [[ ! "$_pid" =~ ^[1-9][0-9]*$ ]]; then _pid=""