From: Florian Forster Date: Sat, 23 Feb 2008 18:25:03 +0000 (+0100) Subject: src/utils_tail.c: Added more error messages. X-Git-Tag: collectd-4.4.0~91^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=55025a66c307823ea3787032c5774afe616d4511;p=collectd.git src/utils_tail.c: Added more error messages. --- diff --git a/src/utils_tail.c b/src/utils_tail.c index b73c1f99..58e027e4 100644 --- a/src/utils_tail.c +++ b/src/utils_tail.c @@ -71,7 +71,11 @@ int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen) int status; if (buflen < 1) + { + ERROR ("utils_tail: cu_tail_readline: buflen too small: " + "%i bytes.", buflen); return (-1); + } if (stat (obj->file, &stat_now) != 0) { @@ -91,11 +95,14 @@ int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen) */ FILE *new_fd; + DEBUG ("utils_tail: cu_tail_readline: (Re)Opening %s..", + obj->file); + new_fd = fopen (obj->file, "r"); if (new_fd == NULL) { char errbuf[1024]; - ERROR ("cu_tail_readline: open (%s) failed: %s", + ERROR ("utils_tail: cu_tail_readline: open (%s) failed: %s", obj->file, sstrerror (errno, errbuf, sizeof (errbuf))); @@ -125,10 +132,14 @@ int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen) status = 0; if (fgets (buf, buflen, obj->fd) == NULL) { - if (feof (obj->fd) == 0) + if (feof (obj->fd) != 0) buf[0] = '\0'; else /* an error occurred */ + { + ERROR ("utils_tail: cu_tail_readline: fgets returned " + "an error."); status = -1; + } } if (status == 0) @@ -142,15 +153,27 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback, { int status; - while ((status = cu_tail_readline (obj, buf, buflen)) == 0) + while (42) { + status = cu_tail_readline (obj, buf, buflen); + if (status != 0) + { + ERROR ("utils_tail: cu_tail_read: cu_tail_readline " + "failed."); + break; + } + /* check for EOF */ if (buf[0] == '\0') break; status = callback (data, buf, buflen); if (status != 0) + { + ERROR ("utils_tail: cu_tail_read: callback returned " + "status %i.", status); break; + } } return status;