interactive-evdev: switch from epoll(2) to poll(2) Turns out FreeBSD supports evdev, so this toll can work on it; however it does not support epoll, so switch to poll, which is portable. Reported-by: Evgeniy Khramtsov <evgeniy@khramtsov.org> Signed-off-by: Ran Benita <ran@unusedvar.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
diff --git a/tools/interactive-evdev.c b/tools/interactive-evdev.c
index 9c8c94e..6b7c8a1 100644
--- a/tools/interactive-evdev.c
+++ b/tools/interactive-evdev.c
@@ -31,6 +31,7 @@
#include <getopt.h>
#include <limits.h>
#include <locale.h>
+#include <poll.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
@@ -38,7 +39,6 @@
#include <string.h>
#include <unistd.h>
-#include <sys/epoll.h>
#include <linux/input.h>
#include "xkbcommon/xkbcommon.h"
@@ -313,33 +313,25 @@ read_keyboard(struct keyboard *kbd)
static int
loop(struct keyboard *kbds)
{
- int i, ret = 1;
- int epfd = -1;
struct keyboard *kbd;
- struct epoll_event ev;
- struct epoll_event evs[16];
+ nfds_t nfds, i;
+ struct pollfd *fds = NULL;
+ int ret;
- epfd = epoll_create1(0);
- if (epfd < 0) {
- fprintf(stderr, "Couldn't create epoll instance: %s\n",
- strerror(errno));
+ for (kbd = kbds, nfds = 0; kbd; kbd = kbd->next, nfds++) {}
+ fds = calloc(nfds, sizeof(*fds));
+ if (fds == NULL) {
+ fprintf(stderr, "Out of memory");
goto out;
}
- for (kbd = kbds; kbd; kbd = kbd->next) {
- memset(&ev, 0, sizeof(ev));
- ev.events = EPOLLIN;
- ev.data.ptr = kbd;
- ret = epoll_ctl(epfd, EPOLL_CTL_ADD, kbd->fd, &ev);
- if (ret) {
- fprintf(stderr, "Couldn't add %s to epoll: %s\n",
- kbd->path, strerror(errno));
- goto out;
- }
+ for (i = 0, kbd = kbds; kbd; kbd = kbd->next, i++) {
+ fds[i].fd = kbd->fd;
+ fds[i].events = POLLIN;
}
while (!terminate) {
- ret = epoll_wait(epfd, evs, 16, -1);
+ ret = poll(fds, nfds, -1);
if (ret < 0) {
if (errno == EINTR)
continue;
@@ -348,18 +340,19 @@ loop(struct keyboard *kbds)
goto out;
}
- for (i = 0; i < ret; i++) {
- kbd = evs[i].data.ptr;
- ret = read_keyboard(kbd);
- if (ret) {
- goto out;
+ for (i = 0, kbd = kbds; kbd; kbd = kbd->next, i++) {
+ if (fds[i].revents != 0) {
+ ret = read_keyboard(kbd);
+ if (ret) {
+ goto out;
+ }
}
}
}
ret = 0;
out:
- close(epfd);
+ free(fds);
return ret;
}
diff --git a/tools/xkbcli-interactive-evdev.1 b/tools/xkbcli-interactive-evdev.1
index be1b70f..58be555 100644
--- a/tools/xkbcli-interactive-evdev.1
+++ b/tools/xkbcli-interactive-evdev.1
@@ -14,7 +14,7 @@
.Nm
is a commandline tool to interactively debug XKB keymaps by listening to
.Pa /dev/input/eventX
-evdev devices (Linux).
+evdev devices.
.
.Pp
.Nm
diff --git a/tools/xkbcli.1 b/tools/xkbcli.1
index 9ea0416..8bd13bf 100644
--- a/tools/xkbcli.1
+++ b/tools/xkbcli.1
@@ -40,7 +40,7 @@ Interactive debugger for XKB keymaps for Wayland, see
.Xr xkbcli\-interactive\-wayland 1
.
.It Ic interactive\-evdev
-Interactive debugger for XKB keymaps for evdev (Linux), see
+Interactive debugger for XKB keymaps for evdev, see
.Xr xkbcli\-interactive\-evdev 1
.
.It Ic list
diff --git a/tools/xkbcli.c b/tools/xkbcli.c
index 1f3ed3f..75f72fe 100644
--- a/tools/xkbcli.c
+++ b/tools/xkbcli.c
@@ -55,7 +55,7 @@ usage(void)
#endif
#if HAVE_XKBCLI_INTERACTIVE_EVDEV
" interactive-evdev\n"
- " Interactive debugger for XKB keymaps for evdev (Linux)\n"
+ " Interactive debugger for XKB keymaps for evdev\n"
"\n"
#endif
#if HAVE_XKBCLI_COMPILE_KEYMAP