From 51f3adcc08d0ec9aea5c09dc6ac26c44d91e1258 Mon Sep 17 00:00:00 2001 From: jkoshy Date: Sat, 9 Jul 2005 17:12:30 +0000 Subject: [PATCH] Fix a bug in pmclog_read() that causes it to return with a false error when a log record crosses an internal buffer boundary. Approved by: re (scottl) --- lib/libpmc/pmclog.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/libpmc/pmclog.c b/lib/libpmc/pmclog.c index a6b70b5f5bb5..e5dd2fc2da16 100644 --- a/lib/libpmc/pmclog.c +++ b/lib/libpmc/pmclog.c @@ -411,6 +411,7 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len, int pmclog_read(void *cookie, struct pmclog_ev *ev) { + int retval; ssize_t nread; struct pmclog_parse_state *ps; @@ -435,6 +436,7 @@ pmclog_read(void *cookie, struct pmclog_ev *ev) * can return EOF. */ if (ps->ps_fd != PMCLOG_FD_NONE) { + refill: nread = read(ps->ps_fd, ps->ps_buffer, PMCLOG_BUFFER_SIZE); @@ -454,10 +456,21 @@ pmclog_read(void *cookie, struct pmclog_ev *ev) assert(ps->ps_len > 0); + + /* Retrieve one event from the byte stream. */ + retval = pmclog_get_event(ps, &ps->ps_data, &ps->ps_len, ev); + /* - * Retrieve one event from the byte stream. + * If we need more data and we have a configured fd, try read + * from it. */ - return pmclog_get_event(ps, &ps->ps_data, &ps->ps_len, ev); + if (retval < 0 && ev->pl_state == PMCLOG_REQUIRE_DATA && + ps->ps_fd != -1) { + assert(ps->ps_len == 0); + goto refill; + } + + return retval; } /*