From bdb0488151a45a510c6ec214e2618af19a17b9c1 Mon Sep 17 00:00:00 2001 From: Gamal Moussa <145904979+tree-1917@users.noreply.github.com> Date: Thu, 20 Nov 2025 09:49:24 +0200 Subject: [PATCH] refactor: replace PID cleanup with loop (#1579) --- src/power.sh | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/power.sh b/src/power.sh index 98a6f73..2f56b72 100644 --- a/src/power.sh +++ b/src/power.sh @@ -76,6 +76,12 @@ finish() { local pid local cnt=0 local reason=$1 + local pids=( + "/var/run/tpm.pid" + "/var/run/wsdd.pid" + "/var/run/samba/nmbd.pid" + "/var/run/samba/smbd.pid" + ) touch "$QEMU_END" @@ -114,21 +120,12 @@ finish() { fi fi - pid="/var/run/tpm.pid" - [ -s "$pid" ] && pKill "$(<"$pid")" - rm -f "$pid" - - pid="/var/run/wsdd.pid" - [ -s "$pid" ] && pKill "$(<"$pid")" - rm -f "$pid" - - pid="/var/run/samba/nmbd.pid" - [ -s "$pid" ] && pKill "$(<"$pid")" - rm -f "$pid" - - pid="/var/run/samba/smbd.pid" - [ -s "$pid" ] && pKill "$(<"$pid")" - rm -f "$pid" + for pid in "${pids[@]}"; do + if [[ -s "$pid" ]]; then + pKill "$(cat "$pid")" + fi + rm -f "$pid" + done closeNetwork