X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Futils_tail.c;h=9d05fe11b5f9228e9862c863ff3f0bc8170acf52;hp=eaf8f738d71e163d628fdfca13f0f32c3678c3a1;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hpb=3f2f61c7d74d9204405a4b0c21390451c98665a7 diff --git a/src/utils_tail.c b/src/utils_tail.c index eaf8f738..9d05fe11 100644 --- a/src/utils_tail.c +++ b/src/utils_tail.c @@ -18,7 +18,7 @@ * * Author: * Luke Heberling - * Florian Forster + * Florian Forster * * Description: * Encapsulates useful code for plugins which must watch for appends to @@ -162,6 +162,7 @@ int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen) /* Try to read from the filehandle. If that succeeds, everything appears to * be fine and we can return. */ + clearerr (obj->fh); if (fgets (buf, buflen, obj->fh) != NULL) { buf[buflen - 1] = 0; @@ -219,6 +220,8 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback, while (42) { + size_t len; + status = cu_tail_readline (obj, buf, buflen); if (status != 0) { @@ -231,6 +234,14 @@ int cu_tail_read (cu_tail_t *obj, char *buf, int buflen, tailfunc_t *callback, if (buf[0] == 0) break; + len = strlen (buf); + while (len > 0) { + if (buf[len - 1] != '\n') + break; + buf[len - 1] = '\0'; + len--; + } + status = callback (data, buf, buflen); if (status != 0) {