diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2007-05-29 19:00:15 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2007-05-29 19:00:15 +0200 |
commit | 701639c00d851f7f829ab6559e2fbd1d229ee298 (patch) | |
tree | 195b9b82799d7549912f86f9cac26016f0c1d2ae | |
parent | 9d114f58550b7fd582d1328e95592deca6012f95 (diff) |
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
-rw-r--r-- | inotail.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -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) { |