summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-06-15 12:31:35 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-06-15 12:31:35 +0200
commit47455d3bea4b2f2ed96a1e86fafd8801fe148292 (patch)
tree4026e6438884aa8f4493b340a31e58a7ff57b178
parent82ffa4b8fcfdcd4ec98563daa06ec135f66ad181 (diff)
parentd440e6dd7cb3db1f0c7b6723c098c5c31c530919 (diff)
Merge branch 'master' into pipe
-rw-r--r--inotail.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/inotail.c b/inotail.c
index 912db03..28eebfd 100644
--- a/inotail.c
+++ b/inotail.c
@@ -92,10 +92,9 @@ static void usage(const int status)
static inline void setup_file(struct file_struct *f)
{
- f->fd = -1;
+ f->fd = f->i_watch = -1;
f->st_size = 0;
f->ignore = 0;
- f->i_watch = -1;
}
static void ignore_file(struct file_struct *f)
@@ -220,10 +219,8 @@ static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes)
if (from_begin) {
if (n_bytes > 0)
offset = (off_t) n_bytes - 1;
- } else {
- if ((off_t) n_bytes < f->st_size)
- offset = f->st_size - (off_t) n_bytes;
- }
+ } else if ((off_t) n_bytes < f->st_size)
+ offset = f->st_size - (off_t) n_bytes;
return offset;
}
@@ -504,21 +501,15 @@ static int watch_files(struct file_struct *files, int n_files)
ssize_t len;
int ev_idx = 0;
- /* 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);
- }
+ len = read(ifd, buf, (n_files * INOTIFY_BUFLEN));
+ if (unlikely(len < 0)) {
+ /* Some form of signal, likely ^Z/fg's STOP and CONT interrupted the inotify read, retry */
+ if (errno == EINTR || errno == EAGAIN)
+ continue; /* Keep trying */
+ 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) {