From 6c881352db2c4200b89b3d9700e7353f36ae823f Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 17 Sep 2007 23:44:04 +0200 Subject: inotail.c: Correct error handling in tail_pipe_lines() --- inotail.c | 11 +++++++---- 1 file 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; -- cgit v1.2.3-54-g00ecf