summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2006-08-20 19:13:00 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2006-08-20 19:13:00 +0200
commitd6c08be03ce12e077cca5c292e128913572578bc (patch)
tree6272244cec0ab63fb6dd814a4bb3ae1ed3e50230
parent3b0d7556897bd0fb296081ae5b4d4866409e7d2f (diff)
Close open fd's on failed fstat()
-rw-r--r--inotail.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/inotail.c b/inotail.c
index c7c20c8..7902b18 100644
--- a/inotail.c
+++ b/inotail.c
@@ -136,6 +136,7 @@ static int tail_file(struct file_struct *f, int n_lines, char mode)
if (fstat(f->fd, &finfo) < 0) {
fprintf(stderr, "Error: Could not stat file '%s' (%s)\n", f->name, strerror(errno));
+ close(f->fd);
return -1;
}
@@ -227,6 +228,7 @@ static int watch_files(struct file_struct *f, int n_files)
fil->ignore = 1;
n_ignored++;
fprintf(stderr, "Error: Could not stat file '%s' (%s)\n", f->name, strerror(errno));
+ close(fil->fd);
continue;
}
@@ -247,10 +249,10 @@ static int watch_files(struct file_struct *f, int n_files)
write_header(fil->name);
memset(&fbuf, 0, sizeof(fbuf));
+
lseek(fil->fd, offset, SEEK_SET);
- while (read(fil->fd, &fbuf, block_size) != 0) {
+ while (read(fil->fd, &fbuf, block_size) != 0)
write(STDOUT_FILENO, fbuf, block_size);
- }
close(fil->fd);
} else if (inev->mask & IN_DELETE_SELF) {