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>
This commit is contained in:
Daniel P. Berrangé 2020-08-27 13:27:00 +01:00
parent de39a045bd
commit 60efffa41b
5 changed files with 32 additions and 57 deletions

View file

@ -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