aboutsummaryrefslogtreecommitdiff
path: root/util/osdep.c
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2020-08-27 13:27:00 +0100
committerDaniel P. Berrangé <berrange@redhat.com>2020-09-16 10:33:48 +0100
commit60efffa41b34cc299fed65b67e2c2641846d592b (patch)
tree2a74b654cdb44e7e384de3be9bddb015d99d1f8b /util/osdep.c
parentde39a045bd8d2b49e4f3d07976622c29d58e0bac (diff)
downloadqemu-60efffa41b34cc299fed65b67e2c2641846d592b.zip
qemu-60efffa41b34cc299fed65b67e2c2641846d592b.tar.gz
qemu-60efffa41b34cc299fed65b67e2c2641846d592b.tar.bz2
monitor: simplify functions for getting a dup'd fdset entry
Currently code has to call monitor_fdset_get_fd, then dup the return fd, and then add the duplicate FD back into the fdset. This dance is overly verbose for the caller and introduces extra failure modes which can be avoided by folding all the logic into monitor_fdset_dup_fd_add and removing monitor_fdset_get_fd entirely. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'util/osdep.c')
-rw-r--r--util/osdep.c19
1 files changed, 3 insertions, 16 deletions
diff --git a/util/osdep.c b/util/osdep.c
index 4829c07..3d94b4d 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -122,7 +122,7 @@ static int fcntl_op_getlk = -1;
/*
* Dups an fd and sets the flags
*/
-static int qemu_dup_flags(int fd, int flags)
+int qemu_dup_flags(int fd, int flags)
{
int ret;
int serrno;
@@ -293,7 +293,7 @@ int qemu_open(const char *name, int flags, ...)
/* Attempt dup of fd from fd set */
if (strstart(name, "/dev/fdset/", &fdset_id_str)) {
int64_t fdset_id;
- int fd, dupfd;
+ int dupfd;
fdset_id = qemu_parse_fdset(fdset_id_str);
if (fdset_id == -1) {
@@ -301,24 +301,11 @@ int qemu_open(const char *name, int flags, ...)
return -1;
}
- fd = monitor_fdset_get_fd(fdset_id, flags);
- if (fd < 0) {
- errno = -fd;
- return -1;
- }
-
- dupfd = qemu_dup_flags(fd, flags);
+ dupfd = monitor_fdset_dup_fd_add(fdset_id, flags);
if (dupfd == -1) {
return -1;
}
- ret = monitor_fdset_dup_fd_add(fdset_id, dupfd);
- if (ret == -1) {
- close(dupfd);
- errno = EINVAL;
- return -1;
- }
-
return dupfd;
}
#endif