[PATCH v4 1/7] pidfile: Make checking binary path in virPidFileRead optional

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 |   21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 1fd6318..f1f721f 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -184,6 +184,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
@@ -209,16 +212,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;
 }
-- 
1.7.3.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]