mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-28 11:56:03 +00:00
fix: Use shared PID reader for helper processes (#1335)
This commit is contained in:
+5
-1
@@ -449,6 +449,7 @@ configureDNS() {
|
||||
local gateway="$6"
|
||||
local upstream="${7:-}"
|
||||
local arguments="$DNSMASQ_OPTS"
|
||||
local pid
|
||||
|
||||
if ! echo "$gateway" > /run/shm/qemu.gw; then
|
||||
error "Failed to write gateway file."
|
||||
@@ -458,7 +459,10 @@ configureDNS() {
|
||||
enabled "${DNSMASQ_DISABLE:-}" && return 0
|
||||
enabled "$DEBUG" && echo "Starting dnsmasq daemon..."
|
||||
|
||||
[ -s "$DNSMASQ_PID" ] && pKill "$(<"$DNSMASQ_PID")"
|
||||
if readPidFile pid "$DNSMASQ_PID"; then
|
||||
pKill "$pid"
|
||||
fi
|
||||
|
||||
rm -f "$DNSMASQ_PID"
|
||||
|
||||
if isNAT; then
|
||||
|
||||
+3
-1
@@ -69,9 +69,11 @@ readQemuPid() {
|
||||
|
||||
local -n _pid="$1"
|
||||
local file
|
||||
local pid
|
||||
|
||||
for file in "$QEMU_START_PID" "$QEMU_PID"; do
|
||||
if [ -s "$file" ] && read -r _pid < "$file"; then
|
||||
if readPidFile pid "$file"; then
|
||||
_pid="$pid"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
+2
-2
@@ -73,7 +73,7 @@ startHostBinary() {
|
||||
pid=$!
|
||||
fi
|
||||
|
||||
echo "$pid" > "$HOST_PID"
|
||||
printf '%s\n' "$pid" > "$HOST_PID"
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -86,7 +86,7 @@ waitForSocket() {
|
||||
|
||||
while [ ! -S "$socket" ]; do
|
||||
|
||||
if ! read -r pid < "$HOST_PID" || ! isAlive "$pid"; then
|
||||
if ! readPidFile pid "$HOST_PID" || ! isAlive "$pid"; then
|
||||
error "qemu-host exited unexpectedly!"
|
||||
exit "$exit_code"
|
||||
fi
|
||||
|
||||
+2
-2
@@ -64,7 +64,7 @@ stopWebServer() {
|
||||
|
||||
local pid
|
||||
|
||||
if [ -s "$WEB_PID" ] && read -r pid < "$WEB_PID" && [ -n "$pid" ]; then
|
||||
if readPidFile pid "$WEB_PID"; then
|
||||
pKill "$pid" 2
|
||||
|
||||
if isAlive "$pid"; then
|
||||
@@ -88,7 +88,7 @@ stopWebsocketServer() {
|
||||
|
||||
local pid
|
||||
|
||||
if [ -s "$WSD_PID" ] && read -r pid < "$WSD_PID" && [ -n "$pid" ]; then
|
||||
if readPidFile pid "$WSD_PID"; then
|
||||
pKill "$pid" 2
|
||||
|
||||
if isAlive "$pid"; then
|
||||
|
||||
+16
-6
@@ -7,6 +7,20 @@ info () { printf "%b%s%b" "\E[1;34m❯ \E[1;36m" "${1:-}" "\E[0m\n"; }
|
||||
error () { printf "%b%s%b" "\E[1;31m❯ " "ERROR: ${1:-}" "\E[0m\n" >&2; }
|
||||
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
|
||||
|
||||
_pid=$(<"$file")
|
||||
|
||||
[[ "$_pid" =~ ^[1-9][0-9]*$ ]]
|
||||
}
|
||||
|
||||
hasFlag() {
|
||||
|
||||
# Match a whitespace-delimited token in /proc/cpuinfo
|
||||
@@ -137,9 +151,7 @@ waitPidFile() {
|
||||
local file="$1"
|
||||
local timeout="${2:-10}"
|
||||
|
||||
[ ! -s "$file" ] && return 0
|
||||
! read -r pid <"$file" && return 0
|
||||
[ -z "$pid" ] && return 0
|
||||
! readPidFile pid "$file" && return 0
|
||||
|
||||
while [ -s "$file" ] && isAlive "$pid"; do
|
||||
sleep 0.2
|
||||
@@ -203,9 +215,7 @@ sKill() {
|
||||
local pid
|
||||
local file="$1"
|
||||
|
||||
[ ! -s "$file" ] && return 0
|
||||
! read -r pid <"$file" && return 0
|
||||
[ -z "$pid" ] && return 0
|
||||
! readPidFile pid "$file" && return 0
|
||||
|
||||
if isAlive "$pid"; then
|
||||
{ kill -15 -- "$pid" || :; } 2>/dev/null
|
||||
|
||||
Reference in New Issue
Block a user