From c28d097c6679d7b46b79fd3b5bdf0853520f9740 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 7 Jun 2017 18:03:54 -0400 Subject: [PATCH] connection.c: refuse to create a notif. iter. when the graph is canceled MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It is useless to create a notification iterator from a connection which belongs to a canceled graph. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- .../babeltrace/graph/connection-internal.h | 7 ++++++ lib/graph/connection.c | 24 +++++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/babeltrace/graph/connection-internal.h b/include/babeltrace/graph/connection-internal.h index 13e7d9ee..fb4f668f 100644 --- a/include/babeltrace/graph/connection-internal.h +++ b/include/babeltrace/graph/connection-internal.h @@ -83,6 +83,13 @@ BT_HIDDEN void bt_connection_remove_iterator(struct bt_connection *conn, struct bt_notification_iterator *iterator); +static inline +struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn) +{ + assert(conn); + return (void *) conn->base.parent; +} + static inline enum bt_connection_status bt_connection_status_from_notification_iterator_status( diff --git a/lib/graph/connection.c b/lib/graph/connection.c index 17cefd9c..72bbb852 100644 --- a/lib/graph/connection.c +++ b/lib/graph/connection.c @@ -303,12 +303,23 @@ bt_private_connection_create_notification_iterator( goto end; } - if (!notification_types) { - BT_LOGD_STR("No notification types: subscribing to all notifications."); - notification_types = all_notif_types; + connection = bt_connection_from_private(private_connection); + + if (bt_graph_is_canceled(bt_connection_borrow_graph(connection))) { + BT_LOGW("Cannot create notification iterator from connection: " + "connection's graph is canceled: " + "conn-addr=%p, upstream-port-addr=%p, " + "upstream-port-name=\"%s\", upstream-comp-addr=%p, " + "upstream-comp-name=\"%s\", graph-addr=%p", + connection, connection->upstream_port, + bt_port_get_name(connection->upstream_port), + upstream_component, + bt_component_get_name(upstream_component), + bt_connection_borrow_graph(connection)); + status = BT_CONNECTION_STATUS_GRAPH_IS_CANCELED; + goto end; } - connection = bt_connection_from_private(private_connection); if (bt_connection_is_ended(connection)) { BT_LOGW("Invalid parameter: connection is ended: " "conn-addr=%p", connection); @@ -316,6 +327,11 @@ bt_private_connection_create_notification_iterator( goto end; } + if (!notification_types) { + BT_LOGD_STR("No notification types: subscribing to all notifications."); + notification_types = all_notif_types; + } + upstream_port = connection->upstream_port; assert(upstream_port); upstream_component = bt_port_get_component(upstream_port); -- 2.34.1