From: Philippe Proulx Date: Fri, 4 Aug 2017 21:42:03 +0000 (-0400) Subject: graph: check if graph has at least one sink to return the NO_SINK status X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=2de524b31c22e92a264e1324a0981fc312516c53 graph: check if graph has at least one sink to return the NO_SINK status Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- diff --git a/include/babeltrace/graph/graph-internal.h b/include/babeltrace/graph/graph-internal.h index 1e8b1b79..677c65bd 100644 --- a/include/babeltrace/graph/graph-internal.h +++ b/include/babeltrace/graph/graph-internal.h @@ -59,6 +59,7 @@ struct bt_graph { bt_bool canceled; bt_bool in_remove_listener; + bt_bool has_sink; struct { GArray *port_added; diff --git a/lib/graph/graph.c b/lib/graph/graph.c index 747a2826..7b013d35 100644 --- a/lib/graph/graph.c +++ b/lib/graph/graph.c @@ -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); }