if (!ctf_move_pos(&dummy, tlen * CHAR_BIT))
packet_filled = 1;
if (packet_filled || ctf_pos_packet(&dummy)) {
- ctf_pos_pad_packet(pos);
+ if (ctf_pos_pad_packet(pos))
+ goto error;
write_packet_header(pos, s_uuid);
write_packet_context(pos);
if (attempt++ == 1) {
#include <babeltrace/context-internal.h>
#include <babeltrace/compat/uuid.h>
#include <babeltrace/endian.h>
+#include <babeltrace/error.h>
#include <babeltrace/trace-debug-info.h>
#include <babeltrace/ctf/ctf-index.h>
#include <inttypes.h>
if (unlikely(pos->offset == EOF))
return EOF;
- ctf_pos_get_event(pos);
+ if (ctf_pos_get_event(pos))
+ return EOF;
/* save the current position as a restore point */
pos->last_offset = pos->offset;
case SEEK_SET: /* Fall-through */
break; /* OK */
default:
- assert(0);
+ ret = -1;
+ goto end;
}
if ((pos->prot & PROT_WRITE) && pos->content_size_loc)
if (ret) {
fprintf(stderr, "[error] Unable to unmap old base: %s.\n",
strerror(errno));
- assert(0);
+ ret = -1;
+ goto end;
}
pos->base_mma = NULL;
}
pos->cur_index = 0;
break;
default:
- assert(0);
+ ret = -1;
+ goto end;
}
pos->content_size = -1U; /* Unknown at this point */
pos->packet_size = WRITE_PACKET_LEN;
case SEEK_CUR:
{
if (pos->offset == EOF) {
- return;
+ ret = 0;
+ goto end;
}
assert(pos->cur_index < pos->packet_index->len);
/* The reader will expect us to skip padding */
case SEEK_SET:
if (index >= pos->packet_index->len) {
pos->offset = EOF;
- return;
+ ret = 0;
+ goto end;
}
pos->cur_index = index;
break;
default:
- assert(0);
+ ret = -1;
+ goto end;
}
if (pos->cur_index >= pos->packet_index->len) {
pos->offset = EOF;
- return;
+ ret = 0;
+ goto end;
}
packet_index = &g_array_index(pos->packet_index,
ctf_update_current_packet_index(&file_stream->parent,
prev_index, packet_index);
+ if (pos->cur_index >= pos->packet_index->len) {
+ pos->offset = EOF;
+ ret = 0;
+ goto end;
+ }
+
/*
* We need to check if we are in trace read or called
* from packet indexing. In this last case, the
if (packet_index->data_offset == -1) {
ret = find_data_offset(pos, file_stream, packet_index);
if (ret < 0) {
- return;
+ ret = -1;
+ goto end;
}
}
pos->content_size = packet_index->content_size;
goto read_next_packet;
} else {
pos->offset = EOF;
- return;
+ ret = 0;
+ goto end;
}
}
/* map new base. Need mapping length from header. */
ret = generic_rw(&pos->parent, &file_stream->parent.stream_packet_context->p);
assert(!ret);
}
+ ret = 0;
+end:
+ bt_packet_seek_set_error(ret);
}
static
/* Ask for the first packet to get the stream_id. */
packet_seek(&file_stream->pos.parent, 0, SEEK_SET);
+ ret = bt_packet_seek_get_error();
+ if (ret) {
+ goto end;
+ }
stream_id = file_stream->parent.stream_id;
if (stream_id >= td->streams->len) {
fprintf(stderr, "[error] Stream %" PRIu64 " is not declared "
ret = handle_seek_position(index, whence, viewer_stream, pos,
file_stream);
if (ret != 0) {
- return;
+ ret = -1;
+ goto end;
}
retry:
if (!lttng_live_should_quit()) {
fprintf(stderr, "[error] get_next_index failed\n");
}
- return;
+ ret = -1;
+ goto end;
}
printf_verbose("Index received : packet_size : %" PRIu64
", offset %" PRIu64 ", content_size %" PRIu64
file_stream->parent.stream_id = stream_id;
viewer_stream->ctf_stream_id = stream_id;
- return;
+ ret = 0;
+ goto end;
}
pos->packet_size = cur_index->packet_size;
pos->offset = EOF;
if (!lttng_live_should_quit()) {
fprintf(stderr, "[error] get_data_packet failed\n");
+ ret = -1;
+ } else {
+ ret = 0;
}
- return;
+ goto end;
}
viewer_stream->data_pending = 0;
read_packet_header(pos, file_stream);
-
+ ret = 0;
end:
- return;
+ bt_packet_seek_set_error(ret);
}
int lttng_live_create_viewer_session(struct lttng_live_ctx *ctx)
babeltrace/iterator.h \
babeltrace/trace-handle.h \
babeltrace/list.h \
- babeltrace/clock-types.h
+ babeltrace/clock-types.h \
+ babeltrace/error.h
babeltracectfinclude_HEADERS = \
babeltrace/ctf/events.h \
#include <stdio.h>
#include <inttypes.h>
#include <babeltrace/mmap-align.h>
+#include <babeltrace/error.h>
#define LAST_OFFSET_POISON ((int64_t) ~0ULL)
}
static inline
-void ctf_pos_pad_packet(struct ctf_stream_pos *pos)
+int ctf_pos_pad_packet(struct ctf_stream_pos *pos)
{
ctf_packet_seek(&pos->parent, 0, SEEK_CUR);
+ return bt_packet_seek_get_error();
}
/*
* the next packet if we are located at the end of the current packet.
*/
static inline
-void ctf_pos_get_event(struct ctf_stream_pos *pos)
+int ctf_pos_get_event(struct ctf_stream_pos *pos)
{
+ int ret = 0;
+
assert(pos->offset <= pos->content_size);
if (pos->offset == pos->content_size) {
printf_debug("ctf_packet_seek (before call): %" PRId64 "\n",
pos->packet_seek(&pos->parent, 0, SEEK_CUR);
printf_debug("ctf_packet_seek (after call): %" PRId64 "\n",
pos->offset);
+ ret = bt_packet_seek_get_error();
}
+ return ret;
}
void ctf_print_timestamp(FILE *fp, struct ctf_stream_definition *stream,
--- /dev/null
+#ifndef BABELTRACE_ERROR_H
+#define BABELTRACE_ERROR_H
+
+/*
+ * BabelTrace
+ *
+ * Global error accessors.
+ *
+ * Copyright 2018 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/*
+ * bt_packet_seek_get_error: get the return code of the last packet_seek use.
+ *
+ * The packet seek functions defined by the various formats don't return a
+ * value. An implementation that can fail to seek can set a per-thread
+ * packet_seek error to be checked by the caller.
+ *
+ * The error is cleared after access in order to preserve the compatibility
+ * with implementation that don't set an error.
+ */
+int bt_packet_seek_get_error(void);
+
+/*
+ * bt_packet_seek_set_error: set the return code of the last packet_seek use.
+ *
+ * This function sets the per-thread packet_seek error. A value of 0 indicates
+ * no error. Implementations of packet_seek are encouraged to use a negative
+ * value to indicate an error.
+ */
+void bt_packet_seek_set_error(int error);
+
+#endif /* BABELTRACE_ERROR_H */
context.c \
trace-handle.c \
trace-collection.c \
- registry.c
+ registry.c \
+ error.c
libbabeltrace_la_LDFLAGS = -version-info $(BABELTRACE_LIBRARY_VERSION)
--- /dev/null
+/*
+ * BabelTrace
+ *
+ * Global error accessors.
+ *
+ * Copyright 2018 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/error.h>
+
+static __thread int packet_seek_error;
+
+int bt_packet_seek_get_error(void)
+{
+ int ret = packet_seek_error;
+
+ packet_seek_error = 0;
+ return ret;
+}
+
+void bt_packet_seek_set_error(int error)
+{
+ packet_seek_error = error;
+}
continue;
stream_pos->packet_seek(&stream_pos->parent, i, SEEK_SET);
+ ret = bt_packet_seek_get_error();
+ if (ret < 0) {
+ return EOF;
+ }
do {
ret = stream_read_event(cfs);
} while (cfs->parent.real_timestamp < timestamp && ret == 0);
*/
for (i = stream_pos->packet_index->len - 1; i >= 0; i--) {
stream_pos->packet_seek(&stream_pos->parent, i, SEEK_SET);
+ ret = bt_packet_seek_get_error();
+ if (ret < 0) {
+ return EOF;
+ }
count = 0;
/* read each event until we reach the end of the stream */
do {