fix: escape socket path regex metacharacters in pgrep fallback

This commit is contained in:
Dino Korah 2026-03-22 21:47:08 +00:00
parent 53bf54cdb3
commit ccac3a3267
1 changed files with 4 additions and 2 deletions

View File

@ -1685,8 +1685,10 @@ function start_virtiofsd() {
if command -v fuser >/dev/null 2>&1; then
VIRTIOFSD_PID=$(fuser "${VIRTIOFSD_SOCKET}" 2>/dev/null | tr -s ' ' '\n' | grep -m1 '[0-9]')
else
local candidate
candidate=$(pgrep -f "virtiofsd.*${VIRTIOFSD_SOCKET}" 2>/dev/null | head -1)
local candidate socket_pat
# Escape regex metacharacters in the socket path before passing to pgrep -f.
socket_pat=$(printf '%s' "${VIRTIOFSD_SOCKET}" | sed 's/[[\.*^$()+?{}|]/\\&/g')
candidate=$(pgrep -f "virtiofsd.*${socket_pat}" 2>/dev/null | head -1)
if ps -p "${candidate}" -o comm= 2>/dev/null | grep -q 'virtiofsd'; then
VIRTIOFSD_PID="${candidate}"
fi