mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virSocketSendMsgWithFDs: Don't report errors, just set errno
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>
This commit is contained in:
parent
b051762e3e
commit
e82f99283d
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user