]> xenbits.xensource.com Git - libvirt.git/commitdiff
virSocketSendMsgWithFDs: Don't report errors, just set errno
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 2 Feb 2024 11:56:04 +0000 (12:56 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 7 Feb 2024 09:57:00 +0000 (10:57 +0100)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
po/POTFILES
src/ch/ch_process.c
src/util/virsocket.c

index e48b9023e2196ea304da73cb081ea995073f20e8..428919815d95945bcf360e85d9e868e229bf7020 100644 (file)
@@ -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
index 86d3190324699425a323a106f3c81290062f6b82..3265ae90de69d82b61e13c1042dd75cf9e8751a6 100644 (file)
@@ -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;
         }
 
index a4c646e759979836aeec63f60307847ead4162cc..ff06eb15f7163b68f298d995a2d7e039929efd6c 100644 (file)
 
 #include <config.h>
 
-#include "virerror.h"
 #include "virsocket.h"
 #include "virutil.h"
 #include "virfile.h"
-#include "virlog.h"
 
 #include <fcntl.h>
 
-#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 */