diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2006-08-20 19:13:00 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2006-08-20 19:13:00 +0200 |
commit | d6c08be03ce12e077cca5c292e128913572578bc (patch) | |
tree | 6272244cec0ab63fb6dd814a4bb3ae1ed3e50230 | |
parent | 3b0d7556897bd0fb296081ae5b4d4866409e7d2f (diff) |
Close open fd's on failed fstat()
-rw-r--r-- | inotail.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -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) { |