[libvirt] [PATCH] util:Fix with process number and pid file do not match

dubo163 dubo163 at 126.com
Mon Jul 2 11:08:15 UTC 2018


From: dubobo <dubobo at didichuxing.com>

the libvirtd pid file is not match the os process pid number
which is smaller than before.

this would be exist if the libvirtd process coredump or the os
process was killed which the next pid number is smaller.

you can be also edit the pid file to write the longer number than
before,then restart the libvirtd service.

Signed-off-by: dubobo <dubobo at didichuxing.com>
---
 src/util/virpidfile.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 58ab29f..8b0ff99 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -445,6 +445,12 @@ int virPidFileAcquirePath(const char *path,
     }
 
     snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
+    if (ftruncate(fd, 0) < 0) {
+        VIR_FORCE_CLOSE(fd);
+        return -1;
+    }
+
+    lseek(fd, 0, SEEK_SET);
 
     if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
         virReportSystemError(errno,
-- 
1.8.3.1




More information about the libvir-list mailing list