[PATCH v2 2/4] virpidfile: Refactor virPidFileReadPathIfAlive

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

 



If the binary path is not provided check that the pid file is locked by
the owner process.

Signed-off-by: Vasiliy Ulyanov <vulyanov@xxxxxxx>
---
 src/util/virpidfile.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 7069f8343d..8ddc336d6c 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -216,6 +216,26 @@ int virPidFileReadPathIfAlive(const char *path,
 #endif
 
     if (!binPath) {
+        int fd;
+        pid_t ownerPid;
+
+        if ((fd = open(path, O_RDONLY)) < 0)
+            return -1;
+
+        if (virFileGetLockOwner(fd, 0, 1, &ownerPid) < 0) {
+            VIR_FORCE_CLOSE(fd);
+            return -1;
+        }
+
+        if (VIR_CLOSE(fd) < 0)
+            return -1;
+
+        /* A pid file should be locked by the process owning it. */
+        if (ownerPid != retPid) {
+            *pid = -1;
+            return 0;
+        }
+
         /* we only knew the pid, and that pid is alive, so we can
          * return it.
          */
-- 
2.34.1





[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]

  Powered by Linux