From: Yunhee Seo Date: Thu, 22 May 2025 00:50:07 +0000 (+0900) Subject: storage: Change dbus connection as private X-Git-Tag: accepted/tizen/unified/20250612.143602~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65fba41ebbbed17921c64cd49f42853ea80d4329;p=platform%2Fcore%2Fsystem%2Fstoraged.git storage: Change dbus connection as private From the libsyscommon, dbus connection was continuously used in an initialized state. However, it is correct for the user side to use the dbus connection handle after obtaining the connection. Change-Id: I9adf5a2de002b98856cb55203786f8e726c23241 Signed-off-by: Yunhee Seo --- diff --git a/src/block/block.c b/src/block/block.c index 7aa6ee5..ec773a9 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3825,6 +3825,10 @@ static void block_init(void *data) { int ret_val; int i; + dbus_handle_h handle = NULL; + + if (data) + handle = *(dbus_handle_h *)data; udev_init(NULL); @@ -3838,7 +3842,7 @@ static void block_init(void *data) _E("Failed to mount tmpfs to root mount path: %d", ret_val); /* register block manager object and interface */ - ret_val = gdbus_register_object(NULL, STORAGED_PATH_BLOCK_MANAGER, &block_interface); + ret_val = gdbus_register_object(handle, STORAGED_PATH_BLOCK_MANAGER, &block_interface); if (ret_val < 0) _E("Failed to register block interface and methods: %d", ret_val); diff --git a/src/core/main.c b/src/core/main.c index 08d9e8c..b0baa98 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -37,6 +37,7 @@ #define STORAGED_DIR_PATH "/run/storaged" static GMainLoop *loop; +static dbus_handle_h g_handle = NULL; static gboolean handle_signal(gpointer data) { @@ -86,16 +87,15 @@ static int storaged_init(void *data) { guint timer; int ret; - dbus_handle_h handle = NULL; - handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, FALSE); - if (!handle) + g_handle = gdbus_get_connection(G_BUS_TYPE_SYSTEM, TRUE); + if (!g_handle) _E("Failed to get dbus connection."); dir_init(); - modules_init(NULL); + modules_init((void *)&g_handle); - ret = gdbus_request_name(handle, STORAGED_BUS_NAME, dbus_name_acquired, NULL); + ret = gdbus_request_name(g_handle, STORAGED_BUS_NAME, dbus_name_acquired, NULL); if (ret <= 0) { _E("Failed to request bus name."); gdbus_check_name_owner(NULL, STORAGED_BUS_NAME); @@ -116,8 +116,21 @@ static int storaged_init(void *data) static int storaged_exit(void *data) { + int ret = 0; modules_deinit(NULL); + if (!g_handle) + return 0; + + ret = gdbus_free_connection(g_handle); + if (ret < 0) { + _E("Failed to free dbus connection %d", ret); + g_handle = NULL; + return ret; + } + + g_handle = NULL; + return 0; } diff --git a/src/core/modules.c b/src/core/modules.c index 3a84274..c346cc0 100644 --- a/src/core/modules.c +++ b/src/core/modules.c @@ -152,7 +152,7 @@ int modules_init(void *data) module_list = g_list_append(module_list, module); if (plugin->init) - plugin->init(NULL); + plugin->init(data); } if (dp) diff --git a/src/storage/storage.c b/src/storage/storage.c index 5373b2f..fb48251 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -931,13 +931,17 @@ static void storage_config_load(void) static void storage_init(void *data) { int ret_val; + dbus_handle_h handle = NULL; + + if (data) + handle = *(dbus_handle_h *)data; /* UDEV udev_init */ udev_init(NULL); storage_config_load(); - ret_val = gdbus_register_object(NULL, STORAGED_PATH_STORAGE, + ret_val = gdbus_register_object(handle, STORAGED_PATH_STORAGE, &storage_interface); if (ret_val < 0) _E("Failed to register dbus interface and methods: %d", ret_val);