aboutsummaryrefslogtreecommitdiff
path: root/lib/libpmc/pmclog.c
diff options
context:
space:
mode:
authorJoseph Koshy <jkoshy@FreeBSD.org>2005-07-09 17:12:30 +0000
committerJoseph Koshy <jkoshy@FreeBSD.org>2005-07-09 17:12:30 +0000
commit82c83e34dd87815603b55ab92917aea76e46803e (patch)
tree4966c5d0556e0b13ddd62ad9cb282c0f7a4789d0 /lib/libpmc/pmclog.c
parentdc1d9d2e7beefd34a96457d2cab4311cd6e8ddf0 (diff)
downloadsrc-82c83e34dd87815603b55ab92917aea76e46803e.tar.gz
src-82c83e34dd87815603b55ab92917aea76e46803e.zip
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)
Notes
Notes: svn path=/head/; revision=147864
Diffstat (limited to 'lib/libpmc/pmclog.c')
-rw-r--r--lib/libpmc/pmclog.c17
1 files 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;
}
/*