[PATCH 2/6] kvm: qemu: dup the qemu_eventfd() return

Mark McLoughlin
2008-10-30T17:53:25Z

qemu_eventfd() returns two file descriptors, both of which
must be closed when pipe() is used in the absence of eventfd().

Duplicate the eventfd() file descriptor so that closing
both descriptors will work in that case.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
qemu/compatfd.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/qemu/compatfd.c b/qemu/compatfd.c
index cc5ced3..36e37e5 100644
--- a/qemu/compatfd.c
+++ b/qemu/compatfd.c
@@ -118,7 +118,11 @@ int qemu_eventfd(int *fds)

ret = syscall(SYS_eventfd, 0);
if (ret >= 0) {
- fds[0] = fds[1] = ret;
+ fds[0] = ret;
+ if ((fds[1] = dup(ret)) == -1) {
+ close(ret);
+ return -1;
+ }
return 0;
}
#endif
--
1.5.4.3