From 97fc6ccc502804ca5f6bd4e069ed4b8a12cc1bac Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 20 May 2007 21:57:03 +0200 Subject: inotail.c: Some more error checking in tail_pipe() Taken from a patch by Folkert van Heusden --- inotail.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/inotail.c b/inotail.c index 6b7af47..79bad64 100644 --- a/inotail.c +++ b/inotail.c @@ -221,8 +221,13 @@ static ssize_t tail_pipe(struct file_struct *f) write_header(f->name); /* We will just tail everything here */ - while ((rc = read(f->fd, buf, BUFFER_SIZE)) > 0) - write(STDOUT_FILENO, buf, (size_t) rc); + while ((rc = read(f->fd, buf, BUFFER_SIZE)) > 0) { + if (write(STDOUT_FILENO, buf, (size_t) rc)) { + /* e.g. when writing to a pipe which gets closed */ + fprintf(stderr, "Error: Could not write to stdout: %s\n", strerror(errno)); + return -1; + } + } return rc; } -- cgit v1.2.3-54-g00ecf