summaryrefslogtreecommitdiff
path: root/inotail.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-05-29 19:00:15 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-05-29 19:00:15 +0200
commit701639c00d851f7f829ab6559e2fbd1d229ee298 (patch)
tree195b9b82799d7549912f86f9cac26016f0c1d2ae /inotail.c
parent9d114f58550b7fd582d1328e95592deca6012f95 (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
Diffstat (limited to 'inotail.c')
-rw-r--r--inotail.c19
1 files changed, 15 insertions, 4 deletions
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) {