storage: Change dbus connection as private 14/324814/4
authorYunhee Seo <yuni.seo@samsung.com>
Thu, 22 May 2025 00:50:07 +0000 (09:50 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Wed, 28 May 2025 05:25:46 +0000 (14:25 +0900)
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 <yuni.seo@samsung.com>
src/block/block.c
src/core/main.c
src/core/modules.c
src/storage/storage.c

index 7aa6ee56253c2178491a246f0509f2254819232c..ec773a9f5b04e3cbb55d653a227bcff7e1b43934 100644 (file)
@@ -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);
 
index 08d9e8ca93dab81bf6aa13edd94c02bc7cb28109..b0baa98293cecbede187f2548c5ca85d4169d69b 100644 (file)
@@ -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;
 }
 
index 3a84274512e27b9bc095f5d2cc22140983150a8b..c346cc08c69cbe1ebeedac181053a84886fddb2c 100644 (file)
@@ -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)
index 5373b2ff650865d59c1daf2c9f02a9c9076acfba..fb482519414adc64ffaaf4ea59e64adfebb019b8 100644 (file)
@@ -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);