diff options
author | jkoshy <jkoshy@FreeBSD.org> | 2005-07-09 17:12:30 +0000 |
---|---|---|
committer | jkoshy <jkoshy@FreeBSD.org> | 2005-07-09 17:12:30 +0000 |
commit | 51f3adcc08d0ec9aea5c09dc6ac26c44d91e1258 (patch) | |
tree | 4966c5d0556e0b13ddd62ad9cb282c0f7a4789d0 /lib | |
parent | 93ae007c34b5a61e3d494d72d4a7e8378390d83d (diff) | |
download | FreeBSD-src-51f3adcc08d0ec9aea5c09dc6ac26c44d91e1258.zip FreeBSD-src-51f3adcc08d0ec9aea5c09dc6ac26c44d91e1258.tar.gz |
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)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libpmc/pmclog.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/libpmc/pmclog.c b/lib/libpmc/pmclog.c index a6b70b5..e5dd2fc 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; } /* |