]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util:Fix with process number and pid file do not match
authorBobo Du <dubo163@126.com>
Wed, 4 Jul 2018 03:55:51 +0000 (23:55 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Jul 2018 06:10:53 +0000 (08:10 +0200)
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: Bobo Du <dubo163@126.com>
src/util/virpidfile.c

index 58ab29f77f2cfb8583447112dae77a07446bc627..1a85d438a7b56d9d6d099d377daf653f2e501191 100644 (file)
@@ -446,6 +446,14 @@ int virPidFileAcquirePath(const char *path,
 
     snprintf(pidstr, sizeof(pidstr), "%lld", (long long) pid);
 
+    if (ftruncate(fd, 0) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to truncate pid file '%s'"),
+                             path);
+        VIR_FORCE_CLOSE(fd);
+        return -1;
+    }
+
     if (safewrite(fd, pidstr, strlen(pidstr)) < 0) {
         virReportSystemError(errno,
                              _("Failed to write to pid file '%s'"),