From d42889411bdc848ef3d027eb9e011271ad2ce29a Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Thu, 26 Dec 2013 00:44:55 -0800 Subject: [PATCH] Make EOF fatal --- keystroke-timestamps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index d25d572..e370b22 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -43,8 +43,12 @@ int main (int argc, char **argv) if (select(fd+1, &ready_inputs, NULL, NULL, NULL) != 1) { err(EX_IOERR, "select"); } - if (read(fd, &i, sizeof(i)) != sizeof(i)) { - break; + int read_return = read(fd, &i, sizeof(i)); + if (read_return == -1) { + err(EX_IOERR, "read"); + } + if (read_return != sizeof(i)) { + errx(EX_IOERR, "Unexpected EOF"); } if (i.type == 1 && i.value == 1) { if (print_usec) { -- 2.51.2