From 1c42619640aed97cd928b79360b6662cb7598ece Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Wed, 10 Jun 2020 10:11:20 -0700 Subject: [PATCH] mesh: Add timeout to GetManagedObjects call Switch to using dbus_send_with_timeout when making a request to get managed objects from an application. Change-Id: I5c95b22e0cafa36133ffb5bff1e76764fb4cf398 Signed-off-by: anuj.bhumiya --- mesh/node.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/mesh/node.c b/mesh/node.c index 18c7285..3a9b341 100644 --- a/mesh/node.c +++ b/mesh/node.c @@ -1475,7 +1475,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) struct keyring_net_key net_key; uint8_t dev_key[16]; - if (l_dbus_message_is_error(msg)) { + if (!msg || l_dbus_message_is_error(msg)) { l_error("Failed to get app's dbus objects"); goto fail; } @@ -1632,8 +1632,7 @@ static void get_managed_objects_cb(struct l_dbus_message *msg, void *user_data) fail: /* Handle failed requests */ - if (node) - node_remove(node); + node_remove(node); if (req->type == REQUEST_TYPE_JOIN) req->join_ready_cb(NULL, NULL); @@ -1644,6 +1643,20 @@ fail: l_free(req->import); } +static void send_managed_objects_request(const char *destination, + const char *path, + struct managed_obj_request *req) +{ + struct l_dbus_message *msg; + + msg = l_dbus_message_new_method_call(dbus_get_bus(), destination, path, + L_DBUS_INTERFACE_OBJECT_MANAGER, + "GetManagedObjects"); + l_dbus_message_set_arguments(msg, ""); + dbus_send_with_timeout(dbus_get_bus(), msg, get_managed_objects_cb, + req, l_free, DEFAULT_DBUS_TIMEOUT); +} + /* Establish relationship between application and mesh node */ void node_attach(const char *app_root, const char *sender, uint64_t token, node_ready_func_t cb, void *user_data) @@ -1697,11 +1710,7 @@ void node_join(const char *app_root, const char *sender, const uint8_t *uuid, req->join_ready_cb = cb; req->type = REQUEST_TYPE_JOIN; - l_dbus_method_call(dbus_get_bus(), sender, app_root, - L_DBUS_INTERFACE_OBJECT_MANAGER, - "GetManagedObjects", NULL, - get_managed_objects_cb, - req, l_free); + send_managed_objects_request(sender, app_root, req); } void node_import(const char *app_root, const char *sender, const uint8_t *uuid, @@ -1731,11 +1740,7 @@ void node_import(const char *app_root, const char *sender, const uint8_t *uuid, req->type = REQUEST_TYPE_IMPORT; - l_dbus_method_call(dbus_get_bus(), sender, app_root, - L_DBUS_INTERFACE_OBJECT_MANAGER, - "GetManagedObjects", NULL, - get_managed_objects_cb, - req, l_free); + send_managed_objects_request(sender, app_root, req); } void node_create(const char *app_root, const char *sender, const uint8_t *uuid, @@ -1751,11 +1756,7 @@ void node_create(const char *app_root, const char *sender, const uint8_t *uuid, req->pending_msg = user_data; req->type = REQUEST_TYPE_CREATE; - l_dbus_method_call(dbus_get_bus(), sender, app_root, - L_DBUS_INTERFACE_OBJECT_MANAGER, - "GetManagedObjects", NULL, - get_managed_objects_cb, - req, l_free); + send_managed_objects_request(sender, app_root, req); } static void build_element_config(void *a, void *b) -- 2.7.4