From a9258ceda1c9a550750a9af8a99130cf6b87c474 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Wed, 4 Sep 2013 11:04:58 -0700 Subject: [PATCH 1/1] Add proper error reporting for open failures --- keystroke-timestamps.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index 670b43c..5322e6b 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -2,12 +2,17 @@ #include #include #include +#include +#include int main () { struct input_event i; int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY); - while (fd && read(fd, &i, sizeof(i)) == sizeof(i)) { + if (fd < 0) { + err(EX_NOINPUT, "Could not open keyboard event file"); + } + while (read(fd, &i, sizeof(i)) == sizeof(i)) { if (i.type == 1 && i.value == 1) { printf("%ld.%ld\n", i.time.tv_sec, i.time.tv_usec); fflush(stdout); -- 2.51.2