[PATCH 2/5] virSocketSendMsgWithFDs: Don't report errors, just set errno

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 <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 */
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux