From 388562e6729bcc7b8e792050ec30017eb566dcf5 Mon Sep 17 00:00:00 2001
From: Craig Anderson <craig.anderson@att.com>
Date: Thu, 14 Sep 2017 10:56:51 -0700
Subject: [PATCH] Check libvirtd based on /proc instead of /var/run

Change libvirtd check to look for pre-existing libvirt processes on the host based on /proc, which is more reliable than pidfiles written under /var/run/ which may be stale or may not be written at all.

Change-Id: I8a08dc7930c15ae90e1c6fb8a5fa3344cca2380f
Closes-Bug: #1715702
---
 libvirt/templates/bin/_libvirt.sh.tpl | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libvirt/templates/bin/_libvirt.sh.tpl b/libvirt/templates/bin/_libvirt.sh.tpl
index ff748b0ef2..97cef23079 100644
--- a/libvirt/templates/bin/_libvirt.sh.tpl
+++ b/libvirt/templates/bin/_libvirt.sh.tpl
@@ -18,11 +18,9 @@ limitations under the License.
 
 set -ex
 
-if [[ -f /var/run/libvirtd.pid ]]; then
-   LIBVIRTD_PID="$(< /var/run/libvirtd.pid)"
-   test -d "/proc/$LIBVIRTD_PID" && \
-   test 'libvirtd' = "$(< /proc/$LIBVIRTD_PID/comm)" && \
-   ( echo "ERROR: Libvirtd daemon is already running" && exit 1 )
+if [ -n "$(cat /proc/*/comm 2>/dev/null | grep libvirtd)" ]; then
+    echo "ERROR: libvirtd daemon already running on host" 1>&2
+    exit 1
 fi
 
 rm -f /var/run/libvirtd.pid