From 701639c00d851f7f829ab6559e2fbd1d229ee298 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 29 May 2007 19:00:15 +0200 Subject: inotail.c: Fix handling of EINTR in watch_files() If inotail gets an EINTR signal while reading inotify events, it breaks. However, a common thing to generate these events is hitting ^Z/fg The patch fixes this shortcoming and allows inotail to be interrupted by EINTR. Patch from Anthony Martinez --- inotail.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'inotail.c') diff --git a/inotail.c b/inotail.c index 4d44145..e0ed410 100644 --- a/inotail.c +++ b/inotail.c @@ -368,10 +368,21 @@ static int watch_files(struct file_struct *files, int n_files) ssize_t len; int ev_idx = 0; - len = read(ifd, buf, (n_files * INOTIFY_BUFLEN)); - if (unlikely(len < 0)) { - fprintf(stderr, "Error: Could not read inotify events (%s)\n", strerror(errno)); - exit(EXIT_FAILURE); + /* Keep trying in the case of EINTR (see below) */ + for (;;) { + len = read(ifd, buf, (n_files * INOTIFY_BUFLEN)); + if (unlikely(len < 0)) { + if (errno == EINTR) { + /* Some form of signal, likely ^Z/fg's STOP and CONT interrupted the inotify read, retry */ + continue; + } else { + fprintf(stderr, "Error: Could not read inotify events (%s)\n", strerror(errno)); + exit(EXIT_FAILURE); + } + } + + /* The read did succeed */ + break; } while (ev_idx < len) { -- cgit v1.2.3-54-g00ecf