summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-09-17 23:44:04 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-09-17 23:44:04 +0200
commit6c881352db2c4200b89b3d9700e7353f36ae823f (patch)
tree4653d0205787476d835b0e54dedb550077c21897
parente46c83b30b4dcf9d0e38803c8ee8cc58c915f9d7 (diff)
inotail.c: Correct error handling in tail_pipe_lines()
-rw-r--r--inotail.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/inotail.c b/inotail.c
index 2676176..fdb2919 100644
--- a/inotail.c
+++ b/inotail.c
@@ -322,14 +322,17 @@ static ssize_t tail_pipe_lines(struct file_struct *f, unsigned long n_lines)
}
}
- write(STDOUT_FILENO, p, tmp->buf + tmp->n_bytes - p);
+ if ((rc = write(STDOUT_FILENO, p, tmp->buf + tmp->n_bytes - p)) <= 0) {
+ /* e.g. when writing to a pipe which gets closed */
+ fprintf(stderr, "Error: Could not write to stdout (%s)\n", strerror(errno));
+ goto out;
+ }
for (tmp = tmp->next; tmp; tmp = tmp->next)
- if (write(STDOUT_FILENO, tmp->buf, tmp->n_bytes) <= 0) {
+ if ((rc = write(STDOUT_FILENO, tmp->buf, tmp->n_bytes)) <= 0) {
/* e.g. when writing to a pipe which gets closed */
fprintf(stderr, "Error: Could not write to stdout (%s)\n", strerror(errno));
- rc = -1;
- break;
+ goto out;
}
rc = 0;