]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
pidfile: Make checking binary path in virPidFileRead optional
authorPeter Krempa <pkrempa@redhat.com>
Thu, 26 Jan 2012 15:25:38 +0000 (16:25 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Feb 2012 14:05:16 +0000 (15:05 +0100)
This patch changes behavior of virPidFileRead to enable passing NULL as
path to the binary the pid file should be checked against to skip this
check. This enables using this function for reading files that have same
semantics as pid files, but belong to unknown processes.

src/util/virpidfile.c

index 9c299673ae139e9e1b42f5ef8366335340425755..83083c09931ab55fb1b88e375479dafebb88b7f3 100644 (file)
@@ -193,6 +193,9 @@ int virPidFileRead(const char *dir,
  * resolves to @binpath. This adds protection against
  * recycling of previously reaped pids.
  *
+ * If @binpath is NULL the check for the executable path
+ * is skipped.
+ *
  * Returns -errno upon error, or zero on successful
  * reading of the pidfile. If the PID was not still
  * alive, zero will be returned, but @pid will be
@@ -218,16 +221,18 @@ int virPidFileReadPathIfAlive(const char *path,
     }
 #endif
 
-    if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) {
-        *pid = -1;
-        return -1;
-    }
+    if (binpath) {
+        if (virAsprintf(&procpath, "/proc/%d/exe", *pid) < 0) {
+            *pid = -1;
+            return -1;
+        }
 
-    if (virFileIsLink(procpath) &&
-        virFileLinkPointsTo(procpath, binpath) == 0)
-        *pid = -1;
+        if (virFileIsLink(procpath) &&
+            virFileLinkPointsTo(procpath, binpath) == 0)
+            *pid = -1;
 
-    VIR_FREE(procpath);
+        VIR_FREE(procpath);
+    }
 
     return 0;
 }