Fix: Add missing lttng_live_should_quit checks
[babeltrace.git] / formats / lttng-live / lttng-live-comm.c
index e3cab91457fbf8ee2b6316a9bc4b31ad6143c7e6..9feb7185c76d0d1cdea4c1e5dfd79dc300849dbc 100644 (file)
@@ -544,6 +544,9 @@ restart:
                printf_verbose("Asking for new streams returns %d\n",
                                ret);
                if (ret < 0) {
+                       if (lttng_live_should_quit()) {
+                               goto end;
+                       }
                        if (ret == -LTTNG_VIEWER_NEW_STREAMS_HUP) {
                                printf_verbose("Session %" PRIu64 " closed\n",
                                                id);
@@ -1065,7 +1068,9 @@ retry:
        ret = get_next_index(session->ctx, viewer_stream, cur_index);
        if (ret < 0) {
                pos->offset = EOF;
-               fprintf(stderr, "[error] get_next_index failed\n");
+               if (!lttng_live_should_quit()) {
+                       fprintf(stderr, "[error] get_next_index failed\n");
+               }
                return;
        }
 
@@ -1115,7 +1120,9 @@ retry:
                goto retry;
        } else if (ret < 0) {
                pos->offset = EOF;
-               fprintf(stderr, "[error] get_data_packet failed\n");
+               if (!lttng_live_should_quit()) {
+                       fprintf(stderr, "[error] get_data_packet failed\n");
+               }
                return;
        }
 
@@ -1429,9 +1436,10 @@ error:
        return -1;
 }
 
-void lttng_live_read(struct lttng_live_ctx *ctx)
+int lttng_live_read(struct lttng_live_ctx *ctx)
 {
-       int ret, i;
+       int ret = -1;
+       int i;
        struct bt_ctf_iter *iter;
        const struct bt_ctf_event *event;
        struct bt_iter_pos begin_pos;
@@ -1489,12 +1497,14 @@ void lttng_live_read(struct lttng_live_ctx *ctx)
                int flags;
 
                if (lttng_live_should_quit()) {
+                       ret = 0;
                        goto end_free;
                }
 
                while (!ctx->session->stream_count) {
                        if (lttng_live_should_quit()
                                        || ctx->session_ids->len == 0) {
+                               ret = 0;
                                goto end_free;
                        }
                        ret = ask_new_streams(ctx);
@@ -1512,11 +1522,16 @@ void lttng_live_read(struct lttng_live_ctx *ctx)
                begin_pos.type = BT_SEEK_BEGIN;
                iter = bt_ctf_iter_create(ctx->bt_ctx, &begin_pos, NULL);
                if (!iter) {
+                       if (lttng_live_should_quit()) {
+                               ret = 0;
+                               goto end;
+                       }
                        fprintf(stderr, "[error] Iterator creation error\n");
                        goto end;
                }
                for (;;) {
                        if (lttng_live_should_quit()) {
+                               ret = 0;
                                goto end_free;
                        }
                        event = bt_ctf_iter_read_event_flags(iter, &flags);
@@ -1547,5 +1562,8 @@ void lttng_live_read(struct lttng_live_ctx *ctx)
 end_free:
        bt_context_put(ctx->bt_ctx);
 end:
-       return;
+       if (lttng_live_should_quit()) {
+               ret = 0;
+       }
+       return ret;
 }
This page took 0.024139 seconds and 4 git commands to generate.