@@ -115,29 +115,3 @@ int qemu_signalfd(const sigset_t *mask)
return qemu_signalfd_compat(mask);
}
-
-int qemu_eventfd(int *fds)
-{
- int ret;
-
-#if defined(CONFIG_EVENTFD)
- ret = syscall(SYS_eventfd, 0);
- if (ret >= 0) {
- fds[0] = ret;
- qemu_set_cloexec(ret);
- if ((fds[1] = dup(ret)) == -1) {
- close(ret);
- return -1;
- }
- qemu_set_cloexec(fds[1]);
- return 0;
- }
-#endif
-
- ret = pipe(fds);
- if (ret != -1) {
- qemu_set_cloexec(fds[0]);
- qemu_set_cloexec(fds[1]);
- }
- return ret;
-}
@@ -40,6 +40,4 @@ struct qemu_signalfd_siginfo {
int qemu_signalfd(const sigset_t *mask);
-int qemu_eventfd(int *fds);
-
#endif
@@ -37,6 +37,10 @@
#include <sys/statvfs.h>
#endif
+#ifdef CONFIG_EVENTFD
+#include <sys/eventfd.h>
+#endif
+
#ifdef _WIN32
#include <windows.h>
#elif defined(CONFIG_BSD)
@@ -285,6 +289,34 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
#ifndef _WIN32
/*
+ * Creates an eventfd that looks like a pipe and has EFD_CLOEXEC set.
+ */
+int qemu_eventfd(int fds[2])
+{
+ int ret;
+
+#ifdef CONFIG_EVENTFD
+ ret = eventfd(0, 0);
+ if (ret >= 0) {
+ fds[0] = ret;
+ qemu_set_cloexec(ret);
+ if ((fds[1] = dup(ret)) == -1) {
+ close(ret);
+ return -1;
+ }
+ qemu_set_cloexec(fds[1]);
+ return 0;
+ }
+
+ if (errno != ENOSYS) {
+ return -1;
+ }
+#endif
+
+ return qemu_pipe(fds);
+}
+
+/*
* Creates a pipe with FD_CLOEXEC set on both file descriptors
*/
int qemu_pipe(int pipefd[2])
@@ -170,6 +170,7 @@ ssize_t qemu_write_full(int fd, const void *buf, size_t count)
void qemu_set_cloexec(int fd);
#ifndef _WIN32
+int qemu_eventfd(int pipefd[2]);
int qemu_pipe(int pipefd[2]);
#endif