heart : remove pipe and fd handler for SyncCpuData 13/130113/1
authorKichan Kwon <k_c.kwon@samsung.com>
Fri, 19 May 2017 07:00:08 +0000 (16:00 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Fri, 19 May 2017 07:00:08 +0000 (16:00 +0900)
- Main thread has replied message because libdbus is not thread-safe
- However, we are using gdbus, so other thread can reply directly

Change-Id: I06325194791203d9c917047e873330f4fad51650
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/heart/heart-cpu.c
src/heart/logging.c

index e2b2507..7c2d443 100644 (file)
@@ -1443,8 +1443,6 @@ static void dbus_heart_sync_cpu_data(GDBusMethodInvocation *invocation, GVariant
        ret = logging_sync(reply);
        if (ret)
                g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret));
-
-       g_object_unref(reply);
 }
 
 static void dbus_heart_save_to_file(GDBusMethodInvocation *invocation, GVariant *params)
index 98b8650..1762d54 100644 (file)
@@ -50,7 +50,6 @@
 #include "config-parser.h"
 #include "notifier.h"
 #include "userinfo-list.h"
-#include "fd-handler.h"
 
 #define LOGGING_BUF_MAX                        1024
 #define LOGGING_PTIORITY               20
@@ -137,9 +136,7 @@ static leveldb_writeoptions_t *woptions;
 
 static struct logging_object *logging_instance = NULL;
 
-static fd_handler_h sync_fd;
 static GDBusMessage *sync_reply;
-static int sync_pipes[2] = {-1, -1};
 
 time_t logging_get_time(int clk_id)
 {
@@ -1394,23 +1391,6 @@ void logging_save_to_storage(int force)
        }
 }
 
-static bool logging_sync_reply(int pipe_fd, void *arg)
-{
-       int ret = -1;
-
-       if (read(pipe_fd, &ret, sizeof(ret)) != sizeof(ret)) {
-               _E("Failed to read the return value of sync thread");
-               ret = -1;
-       }
-
-       g_dbus_message_set_body(sync_reply, g_variant_new("(i)", ret));
-
-       if (d_bus_reply_message(sync_reply) != RESOURCED_ERROR_NONE)
-               _E("Failed to reply sync request");
-
-       return true;
-}
-
 static void *logging_sync_thread_main(void *arg)
 {
        int ret = 0;
@@ -1433,9 +1413,12 @@ static void *logging_sync_thread_main(void *arg)
        }
 
 reply:
-       if (write(sync_pipes[1], &ret, sizeof(ret)) != sizeof(ret))
-               _E("Failed to write the return value of sync thread");
+       g_dbus_message_set_body(sync_reply, g_variant_new("(i)", ret));
 
+       if (d_bus_reply_message(sync_reply) != RESOURCED_ERROR_NONE)
+               _E("Failed to reply sync request");
+
+       g_object_unref(sync_reply);
        logging_sync_thread = 0;
 
        pthread_exit(NULL);
@@ -1443,11 +1426,6 @@ reply:
 
 int logging_sync(GDBusMessage *reply)
 {
-       if (sync_pipes[1] < 0) {
-               _E("Pipe for sync function is not ready");
-               return -1;
-       }
-
        if (logging_sync_thread) {
                _I("logging sync thread %u is already running", (unsigned)logging_sync_thread);
                return logging_sync_thread;
@@ -1602,9 +1580,6 @@ static void logging_thread_stop(void)
        g_source_destroy(logging_update_timer);
        logging_update_timer = NULL;
 
-       /* Delete fd handler for sync thread */
-       remove_fd_read_handler(&sync_fd);
-
        /* Wait thread for working
         *
         * We can wait thread for finishing work by requesting lock
@@ -1698,18 +1673,6 @@ int logging_init(void *data)
        woptions = leveldb_writeoptions_create();
        leveldb_writeoptions_set_sync(woptions, 1);
 
-       /* Create and register pipe for sync function */
-       if (pipe(sync_pipes)) {
-               _E("Failed to create pipe");
-               return RESOURCED_ERROR_FAIL;
-       }
-
-       ret = add_fd_read_handler(sync_pipes[0], logging_sync_reply, NULL, NULL, &sync_fd);
-       if (ret < 0) {
-               _E("Failed to add pipe handler");
-               return RESOURCED_ERROR_FAIL;
-       }
-
        /* Register notifier and timer */
        register_notifier(RESOURCED_NOTIFIER_LOGGING_START, logging_start);
        register_notifier(RESOURCED_NOTIFIER_POWER_OFF, logging_poweroff);
@@ -1734,9 +1697,6 @@ int logging_exit(void *data)
        unregister_notifier(RESOURCED_NOTIFIER_LOGGING_START, logging_start);
        unregister_notifier(RESOURCED_NOTIFIER_POWER_OFF, logging_poweroff);
 
-       close(sync_pipes[0]);
-       close(sync_pipes[1]);
-
        /* flush module cache */
        logging_save_to_storage(true);