Refuse to add port to component when parent graph is canceled
[babeltrace.git] / lib / graph / filter.c
index 4e6db19fd5d59508f9182443a10b7cfe01b2affe..6cae9b3b76da2e163f94bd1ccc49fbe44e91fe51 100644 (file)
@@ -36,6 +36,7 @@
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/graph/notification.h>
 #include <babeltrace/graph/notification-iterator-internal.h>
+#include <babeltrace/graph/graph.h>
 
 BT_HIDDEN
 void bt_component_filter_destroy(struct bt_component *component)
@@ -251,6 +252,7 @@ enum bt_component_status bt_private_component_filter_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.");
@@ -267,6 +269,17 @@ enum bt_component_status bt_private_component_filter_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) {
@@ -315,6 +328,7 @@ enum bt_component_status bt_private_component_filter_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.");
@@ -331,6 +345,17 @@ enum bt_component_status bt_private_component_filter_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/errors */
        port = bt_component_add_output_port(component, name, user_data);
        if (!port) {
This page took 0.024463 seconds and 4 git commands to generate.