From e82f99283dd5d6553d482aef2464366342d1b6e6 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 2 Feb 2024 12:56:04 +0100 Subject: [PATCH] virSocketSendMsgWithFDs: Don't report errors, just set errno MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, virSocketSendMsgWithFDs() reports two errors: 1) if CMSG_FIRSTHDR() fails, 2) if sendmsg() fails. Well, the latter sets an errno, so caller can just use virReportSystemError(). And the former - it is very unlikely to fail because memory for whole control message was allocated just a few lines above. The motivation is to unify behavior of virSocketSendMsgWithFDs() and virSocketSendFD() because the latter is just a subset of the former (will be addressed later). Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- po/POTFILES | 1 - src/ch/ch_process.c | 6 ++++-- src/util/virsocket.c | 14 ++------------ 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/po/POTFILES b/po/POTFILES index e48b9023e2..428919815d 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -327,7 +327,6 @@ src/util/virscsi.c src/util/virscsihost.c src/util/virscsivhost.c src/util/virsecret.c -src/util/virsocket.c src/util/virsocketaddr.c src/util/virstoragefile.c src/util/virstring.c diff --git a/src/ch/ch_process.c b/src/ch/ch_process.c index 86d3190324..3265ae90de 100644 --- a/src/ch/ch_process.c +++ b/src/ch/ch_process.c @@ -558,6 +558,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, g_autofree char *response = NULL; size_t j; size_t tapfd_len; + int saved_errno; int http_res; int rc; @@ -597,6 +598,7 @@ chProcessAddNetworkDevices(virCHDriver *driver, payload = virBufferContentAndReset(&buf); rc = virSocketSendMsgWithFDs(mon_sockfd, payload, tapfds, tapfd_len); + saved_errno = errno; /* Close sent tap fds in Libvirt, as they have been dup()ed in CH */ for (j = 0; j < tapfd_len; j++) { @@ -604,8 +606,8 @@ chProcessAddNetworkDevices(virCHDriver *driver, } if (rc < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Failed to send net-add request to CH")); + virReportSystemError(saved_errno, "%s", + _("Failed to send net-add request to CH")); return -1; } diff --git a/src/util/virsocket.c b/src/util/virsocket.c index a4c646e759..ff06eb15f7 100644 --- a/src/util/virsocket.c +++ b/src/util/virsocket.c @@ -19,16 +19,12 @@ #include -#include "virerror.h" #include "virsocket.h" #include "virutil.h" #include "virfile.h" -#include "virlog.h" #include -#define VIR_FROM_THIS VIR_FROM_NONE - #ifdef WIN32 # define FD2SK(fd) _get_osfhandle(fd) @@ -523,7 +519,7 @@ virSocketSendMsgWithFDs(int sock, const char *payload, int *fds, size_t fds_len) cmsg = CMSG_FIRSTHDR(&msg); /* check to eliminate "potential null pointer dereference" errors during build */ if (!cmsg) { - virReportSystemError(EFAULT, "%s", _("Couldn't fit control msg header in msg")); + errno = ENOSPC; return -1; } @@ -536,11 +532,6 @@ virSocketSendMsgWithFDs(int sock, const char *payload, int *fds, size_t fds_len) ret = sendmsg(sock, &msg, 0); } while (ret < 0 && errno == EINTR); - if (ret < 0) { - virReportSystemError(errno, "%s", _("sendmsg failed")); - return -1; - } - return ret; } @@ -565,8 +556,7 @@ virSocketSendMsgWithFDs(int sock G_GNUC_UNUSED, int *fds G_GNUC_UNUSED, size_t fds_len G_GNUC_UNUSED) { - virReportSystemError(ENOSYS, "%s", - _("FD passing is not supported on this platform")); + errno = ENOSYS; return -1; } #endif /* WIN32 */