[PATCH evemu 3/5] evemu-record: move grab testing into a helper function
Peter Hutterer
peter.hutterer at who-t.net
Thu Feb 25 00:41:52 UTC 2016
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
tools/evemu-record.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/evemu-record.c b/tools/evemu-record.c
index 9d215ab..3cca151 100644
--- a/tools/evemu-record.c
+++ b/tools/evemu-record.c
@@ -41,6 +41,7 @@
#define _GNU_SOURCE
#include "evemu.h"
+#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
@@ -82,6 +83,19 @@ static void handler (int sig __attribute__((unused)))
}
}
+static inline bool test_grab_device(int fd)
+{
+ if (ioctl(fd, EVIOCGRAB, (void*)1) < 0) {
+ fprintf(stderr, "error: this device is grabbed and I cannot record events\n");
+ fprintf(stderr, "see the evemu-record man page for more information\n");
+ return false;
+ } else {
+ ioctl(fd, EVIOCGRAB, (void*)0);
+ }
+
+ return true;
+}
+
enum mode {
EVEMU_RECORD,
EVEMU_DESCRIBE
@@ -146,12 +160,8 @@ int main(int argc, char *argv[])
int clockid = CLOCK_MONOTONIC;
ioctl(fd, EVIOCSCLOCKID, &clockid);
#endif
- if (ioctl(fd, EVIOCGRAB, (void*)1) < 0) {
- fprintf(stderr, "error: this device is grabbed and I cannot record events\n");
- fprintf(stderr, "see the evemu-record man page for more information\n");
+ if (!test_grab_device(fd))
goto out;
- } else
- ioctl(fd, EVIOCGRAB, (void*)0);
fprintf(output, "################################\n");
fprintf(output, "# Waiting for events #\n");
--
2.5.0
More information about the Input-tools
mailing list