]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch_monitor: Report OS error when removing socket fails
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 11 Nov 2024 13:45:43 +0000 (14:45 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 12 Nov 2024 08:11:47 +0000 (09:11 +0100)
When removing a socket in virCHMonitorClose() fails, a warning is
printed. But it doesn't contain errno nor g_strerror() which may
shed more light into why removing of the socket failed.

Oh, and since virCHMonitorClose() is registered as autoptr
cleanup for virCHMonitor() it may happen that virCHMonitorClose()
is called with mon->socketpath allocated but file not existing
yet (see virCHMonitorNew()). Thus ignore ENOENT and do not print
warning in that case - the file doesn't exist anyways.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/ch/ch_monitor.c

index 18ca5a764e0441c21361763ca307c8105a81df8c..935239a721a1293283c6569708f21209b08a67f9 100644 (file)
@@ -622,9 +622,10 @@ void virCHMonitorClose(virCHMonitor *mon)
         curl_easy_cleanup(mon->handle);
 
     if (mon->socketpath) {
-        if (virFileRemove(mon->socketpath, -1, -1) < 0) {
-            VIR_WARN("Unable to remove CH socket file '%s'",
-                     mon->socketpath);
+        if (virFileRemove(mon->socketpath, -1, -1) < 0 &&
+            errno != ENOENT) {
+            VIR_WARN("Unable to remove CH socket file '%s': %s",
+                     mon->socketpath, g_strerror(errno));
         }
         g_clear_pointer(&mon->socketpath, g_free);
     }