From 28362f2bcb7fe869c6bc1b078ceab41483fd69a6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 28 Jan 2015 17:07:35 -0500 Subject: [PATCH] Fix: lazy-mmap() streams when flushing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This fixes an issue when empty streams are created as the stream creation will mmap() the file in preparation for the first event. This results in "empty" stream files ending up with a non-zero size which is invalid since no packet headers are found by the reader. This change ensures that stream files are only mmap'ed on the first stream flush and that empty streams are stored as size-0 files. Signed-off-by: Jérémie Galarneau --- formats/ctf/ctf.c | 2 -- formats/ctf/ir/stream.c | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 40da01da..5436c2a7 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -768,8 +768,6 @@ int ctf_init_pos(struct ctf_stream_pos *pos, struct bt_trace_descriptor *trace, pos->parent.rw_table = write_dispatch_table; pos->parent.event_cb = ctf_write_event; pos->parent.trace = trace; - if (fd >= 0) - ctf_packet_seek(&pos->parent, 0, SEEK_SET); /* position for write */ break; default: assert(0); diff --git a/formats/ctf/ir/stream.c b/formats/ctf/ir/stream.c index 6a71466c..1d14abd6 100644 --- a/formats/ctf/ir/stream.c +++ b/formats/ctf/ir/stream.c @@ -702,10 +702,8 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream) goto end; } - if (stream->flushed_packet_count) { - /* ctf_init_pos has already initialized the first packet */ - ctf_packet_seek(&stream->pos.parent, 0, SEEK_CUR); - } + /* mmap the next packet */ + ctf_packet_seek(&stream->pos.parent, 0, SEEK_CUR); ret = bt_ctf_field_serialize(stream->packet_header, &stream->pos); if (ret) { -- 2.34.1