Refuse to add port to component when parent graph is canceled
[babeltrace.git] / lib / graph / sink.c
index b2088139f080bfe7bccb89ea43666bcd8dedac5c..063539f2acd3c0fd24d02acb5ab7385d40066e50 100644 (file)
@@ -34,6 +34,7 @@
 #include <babeltrace/graph/component-sink-internal.h>
 #include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/notification.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_sink_destroy(struct bt_component *component)
@@ -205,6 +206,7 @@ enum bt_component_status bt_private_component_sink_add_input_private_port(
        struct bt_port *port = NULL;
        struct bt_component *component =
                bt_component_from_private(private_component);
+       struct bt_graph *graph;
 
        if (!component) {
                BT_LOGW_STR("Invalid parameter: component is NULL.");
@@ -221,6 +223,17 @@ enum bt_component_status bt_private_component_sink_add_input_private_port(
                goto end;
        }
 
+       graph = bt_component_borrow_graph(component);
+
+       if (graph && bt_graph_is_canceled(graph)) {
+               BT_LOGW("Cannot add output port to filter component: graph is canceled: "
+                       "comp-addr=%p, comp-name=\"%s\", graph-addr=%p",
+                       component, bt_component_get_name(component),
+                       bt_component_borrow_graph(component));
+               status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED;
+               goto end;
+       }
+
        /* bt_component_add_input_port() logs details/errors */
        port = bt_component_add_input_port(component, name, user_data);
        if (!port) {
This page took 0.023818 seconds and 4 git commands to generate.