Refuse to add port to component when parent graph is canceled
[babeltrace.git] / lib / graph / source.c
index 57244c062584e14d978c40640ae79a015e23300a..b09494f25e6aa384cdffa3c6e816e98da683157a 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/graph/port-internal.h>
 #include <babeltrace/graph/notification-iterator.h>
 #include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_source_destroy(struct bt_component *component)
@@ -170,6 +171,7 @@ enum bt_component_status bt_private_component_source_add_output_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.");
@@ -186,6 +188,17 @@ enum bt_component_status bt_private_component_source_add_output_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_output_port() logs details and errors */
        port = bt_component_add_output_port(component, name, user_data);
        if (!port) {
This page took 0.023709 seconds and 4 git commands to generate.