fix: Read QEMU pid correctly (#1818)

This commit is contained in:
Kroese
2026-07-07 11:03:23 +02:00
committed by GitHub
parent 1e12c90226
commit 35fe5aab9c
+9 -12
View File
@@ -56,15 +56,12 @@ displayReason() {
readQemuPid() { readQemuPid() {
local file="$1" local -n _pid="$1"
local __var="$2"
local pid=""
[ -s "$file" ] || return 1 if [ ! -s "$QEMU_PID" ] || ! read -r _pid <"$QEMU_PID"; then
read -r pid <"$file" || return 1 return 1
[ -n "$pid" ] || return 1 fi
printf -v "$__var" '%s' "$pid"
return 0 return 0
} }
@@ -134,7 +131,7 @@ forceKillQemu() {
local pid="" local pid=""
local display local display
! readQemuPid "$QEMU_PID" pid && return 0 ! readQemuPid pid && return 0
! isAlive "$pid" && return 0 ! isAlive "$pid" && return 0
display=$(displayReason "$reason") display=$(displayReason "$reason")
@@ -200,8 +197,9 @@ finish() {
normalizeTimeout() { normalizeTimeout() {
term_grace=3 # seconds before loop ends to send SIGTERM local term_grace=3 # seconds before loop ends to send SIGTERM
cleanup_grace=3 # seconds reserved after the loop for cleanup local cleanup_grace=3 # seconds reserved after the loop for cleanup
local min
TIMEOUT=$(strip "$TIMEOUT") TIMEOUT=$(strip "$TIMEOUT")
if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]]; then if [[ ! "$TIMEOUT" =~ ^[0-9]+$ ]]; then
@@ -216,7 +214,6 @@ normalizeTimeout() {
cleanup_grace=4 cleanup_grace=4
fi fi
local min
min=$((term_grace + cleanup_grace + 1)) min=$((term_grace + cleanup_grace + 1))
(( TIMEOUT < min )) && (( TIMEOUT = min )) (( TIMEOUT < min )) && (( TIMEOUT = min ))
@@ -304,7 +301,7 @@ graceful_shutdown() {
touch "$QEMU_END" touch "$QEMU_END"
echo && info "Received $1 signal, sending ACPI shutdown signal..." echo && info "Received $1 signal, sending ACPI shutdown signal..."
if ! readQemuPid "$QEMU_PID" pid; then if ! readQemuPid pid; then
warn "QEMU PID file ($QEMU_PID) does not exist?" warn "QEMU PID file ($QEMU_PID) does not exist?"
finish "$code" finish "$code"
fi fi