Fix: handle packet_seek errors
[babeltrace.git] / formats / lttng-live / lttng-live-comm.c
index b61371fc5dba65523eb46f5f1e69b391d2103990..cb871a1318113e4909ba3db8ad3ceae132ed7e05 100644 (file)
@@ -1223,7 +1223,8 @@ void ctf_live_packet_seek(struct bt_stream_pos *stream_pos, size_t index,
        ret = handle_seek_position(index, whence, viewer_stream, pos,
                        file_stream);
        if (ret != 0) {
-               return;
+               ret = -1;
+               goto end;
        }
 
 retry:
@@ -1265,7 +1266,8 @@ 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
@@ -1294,7 +1296,8 @@ retry:
                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;
@@ -1386,15 +1389,18 @@ retry:
                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)
@@ -1499,6 +1505,12 @@ int add_one_trace(struct lttng_live_ctx *ctx,
                ret = 0;
                goto end;
        }
+       /*
+        * add_one_trace can be called recursively if during the
+        * bt_context_add_trace call we need to fetch new streams, so we need to
+        * prevent a recursive call to process our current trace.
+        */
+       trace->in_use = 1;
 
        BT_INIT_LIST_HEAD(&mmap_list.head);
 
@@ -1561,7 +1573,6 @@ int add_one_trace(struct lttng_live_ctx *ctx,
        }
 
        trace->trace_id = ret;
-       trace->in_use = 1;
        printf_verbose("Trace now in use, id = %d\n", trace->trace_id);
 
        goto end;
@@ -1630,9 +1641,13 @@ int add_traces(struct lttng_live_ctx *ctx)
        GHashTableIter it;
        gpointer key;
        gpointer value;
+       unsigned int nr_traces;
 
        printf_verbose("Begin add traces\n");
 
+retry:
+       nr_traces = g_hash_table_size(ctx->session->ctf_traces);
+
        ret = check_traces_metadata(ctx);
        if (ret < 0) {
                goto end;
@@ -1645,6 +1660,15 @@ int add_traces(struct lttng_live_ctx *ctx)
                if (ret < 0) {
                        goto end;
                }
+               /*
+                * If a new trace got added while we were adding the trace, the
+                * iterator is invalid and we have to restart.
+                */
+               if (g_hash_table_size(ctx->session->ctf_traces) != nr_traces) {
+                       printf_verbose("New trace(s) added during add_one_trace()\n");
+                       printf_verbose("JORAJ: GREP HERE\n");
+                       goto retry;
+               }
        }
 
        ret = 0;
This page took 0.023701 seconds and 4 git commands to generate.