diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2007-09-17 23:44:04 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2007-09-17 23:44:04 +0200 |
commit | 6c881352db2c4200b89b3d9700e7353f36ae823f (patch) | |
tree | 4653d0205787476d835b0e54dedb550077c21897 | |
parent | e46c83b30b4dcf9d0e38803c8ee8cc58c915f9d7 (diff) |
inotail.c: Correct error handling in tail_pipe_lines()
-rw-r--r-- | inotail.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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; |