graph: check if graph has at least one sink to return the NO_SINK status
[babeltrace.git] / lib / graph / graph.c
index 747a282601d5622543139a683b15e62572db9515..7b013d358b9d2d03223ea5cdf848aa2ca4153111 100644 (file)
@@ -419,6 +419,12 @@ enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph)
 
        BT_LOGV("Making next sink consume: addr=%p", graph);
 
+       if (!graph->has_sink) {
+               BT_LOGW_STR("Graph has no sink component.");
+               status = BT_GRAPH_STATUS_NO_SINK;
+               goto end;
+       }
+
        if (g_queue_is_empty(graph->sinks_to_consume)) {
                BT_LOGV_STR("Graph's sink queue is empty: end of graph.");
                status = BT_GRAPH_STATUS_END;
@@ -539,6 +545,8 @@ enum bt_graph_status bt_graph_run(struct bt_graph *graph)
                        if (graph->sinks_to_consume->length > 1) {
                                status = BT_GRAPH_STATUS_OK;
                        }
+               } else if (status == BT_GRAPH_STATUS_NO_SINK) {
+                       goto end;
                }
        } while (status == BT_GRAPH_STATUS_OK);
 
@@ -967,6 +975,7 @@ enum bt_graph_status bt_graph_add_component_with_init_method_data(
         * sink queue to be consumed by bt_graph_consume().
         */
        if (bt_component_is_sink(component)) {
+               graph->has_sink = BT_TRUE;
                g_queue_push_tail(graph->sinks_to_consume, component);
        }
 
This page took 0.024076 seconds and 4 git commands to generate.