summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2016-02-25 10:41:52 +1000
committerBenjamin Tissoires <benjamin.tissoires@gmail.com>2016-02-25 10:08:24 +0100
commit79537011b6aada065acbbdb7ac4502800d1664f0 (patch)
tree8c5a9441697b28ab260c228ba8d764502d166b00
parent7b2c1032258355a1a1d30b7973d7fe4df75b6841 (diff)
evemu-record: move grab testing into a helper function
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
-rw-r--r--tools/evemu-record.c20
1 files 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");