if (unlikely(pos->offset == EOF))
return EOF;
- if (pos->content_size == 0) {
- /* Stream is inactive for now (live reading). */
+ /* Stream is inactive for now (live reading). */
+ if (unlikely(pos->content_size == 0))
return EAGAIN;
- }
- /* Packet only contains headers */
- if (pos->offset == pos->content_size)
+
+ /*
+ * Packet seeked to by ctf_pos_get_event() only contains
+ * headers, no event. Consider stream as inactive (live
+ * reading).
+ */
+ if (unlikely(pos->data_offset == pos->content_size))
return EAGAIN;
assert(pos->offset < pos->content_size);
pos->content_size = packet_index->content_size;
pos->packet_size = packet_index->packet_size;
pos->mmap_offset = packet_index->offset;
- if (packet_index->data_offset < packet_index->content_size) {
+ pos->data_offset = packet_index->data_offset;
+ if (pos->data_offset < packet_index->content_size) {
pos->offset = 0; /* will read headers */
- } else if (packet_index->data_offset == packet_index->content_size) {
+ } else if (pos->data_offset == packet_index->content_size) {
/* empty packet */
pos->offset = packet_index->data_offset;
whence = SEEK_CUR;
struct ctf_packet_index ctf_index;
struct ctf_packet_index_file_hdr index_hdr;
struct packet_index index;
- int index_read;
int ret = 0;
int first_packet = 1;
size_t len;
goto error;
}
- while ((index_read = fread(&ctf_index, index_hdr.packet_index_len, 1,
- pos->index_fp)) == 1) {
+ while (fread(&ctf_index, index_hdr.packet_index_len, 1,
+ pos->index_fp) == 1) {
uint64_t stream_id;
memset(&index, 0, sizeof(index));
g_array_append_val(file_stream->pos.packet_cycles_index, index);
}
+ /* Index containing only the header. */
+ if (!file_stream->parent.stream_class) {
+ ret = -1;
+ goto error;
+ }
+
ret = 0;
error:
pos->flags = MAP_PRIVATE;
pos->parent.rw_table = read_dispatch_table;
pos->parent.event_cb = ctf_read_event;
+ pos->priv = mmap_info->priv;
}
static
fprintf(stderr, "Error on ctf_fini_pos\n");
return -1;
}
- ret = close(file_stream->pos.fd);
- if (ret) {
- perror("Error closing file fd");
- return -1;
+ if (file_stream->pos.fd >= 0) {
+ ret = close(file_stream->pos.fd);
+ if (ret) {
+ perror("Error closing file fd");
+ return -1;
+ }
}
return 0;
}
}
}
ctf_destroy_metadata(td);
- ret = close(td->dirfd);
- if (ret) {
- perror("Error closing dirfd");
- return ret;
+ if (td->dirfd >= 0) {
+ ret = close(td->dirfd);
+ if (ret) {
+ perror("Error closing dirfd");
+ return ret;
+ }
}
- ret = closedir(td->dir);
- if (ret) {
- perror("Error closedir");
- return ret;
+ if (td->dir) {
+ ret = closedir(td->dir);
+ if (ret) {
+ perror("Error closedir");
+ return ret;
+ }
}
free(td->metadata_string);
g_free(td);