From d88ebd4374c6391f52b83bff756dbf8826e855c6 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Mon, 11 Nov 2024 14:45:43 +0100 Subject: [PATCH] ch_monitor: Report OS error when removing socket fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/ch/ch_monitor.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c index 18ca5a764e..935239a721 100644 --- a/src/ch/ch_monitor.c +++ b/src/ch/ch_monitor.c @@ -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); }