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

Bobo Du posted 1 patch 5 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1530676551-60739-2-git-send-email-dubo163@126.com
Test syntax-check passed
src/util/virpidfile.c | 8 ++++++++
1 file changed, 8 insertions(+)
[libvirt] [PATCH] util:Fix with process number and pid file do not match
Posted by Bobo Du 5 years, 9 months ago
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 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 58ab29f..1a85d43 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -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'"),
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util:Fix with process number and pid file do not match
Posted by Michal Prívozník 5 years, 9 months ago
On 07/04/2018 05:55 AM, Bobo Du wrote:
> 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 | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 

ACKed and puhsed.

Congratulations on your first libvirt contribution!

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] util:Fix with process number and pid file do not match
Posted by 杜 博 5 years, 9 months ago
Thanks! I will do it better in the future.
At 2018-07-04 13:09:20, "Michal Prívozník" <mprivozn@redhat.com> wrote:
>On 07/04/2018 05:55 AM, Bobo Du wrote:
>> 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 | 8 ++++++++
>>  1 file changed, 8 insertions(+)
>> 
>
>ACKed and puhsed.
>
>Congratulations on your first libvirt contribution!
>
>Michal

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