static struct logging_object *logging_instance = NULL;
+Ecore_Fd_Handler *sync_efd;
+static DBusMessage *sync_reply;
+static int sync_pipes[2] = {-1, -1};
+
time_t logging_get_time(int clk_id)
{
struct timespec ts;
}
}
+static Eina_Bool logging_sync_reply(void *arg, Ecore_Fd_Handler *fd_handler)
+{
+ int pipe_fd;
+ int ret = -1;
+ DBusMessageIter iter;
+
+ if (!ecore_main_fd_handler_active_get(fd_handler, ECORE_FD_READ)) {
+ _E("ecore_main_fd_handler_active_get failed");
+ goto reply;
+ }
+
+ pipe_fd = ecore_main_fd_handler_fd_get(fd_handler);
+ if (pipe_fd < 0) {
+ _E("ecore_main_fd_handler_fd_get failed");
+ goto reply;
+ }
+
+ if (read(pipe_fd, &ret, sizeof(ret)) != sizeof(ret)) {
+ _E("Failed to read the return value of sync thread");
+ ret = -1;
+ }
+
+reply:
+ dbus_message_iter_init_append(sync_reply, &iter);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+
+ if (dbus_message_reply(sync_reply) != RESOURCED_ERROR_NONE)
+ _E("Failed to reply sync request");
+
+ dbus_message_unref(sync_reply);
+
+ return ECORE_CALLBACK_RENEW;
+}
+
static void *logging_sync_thread_main(void *arg)
{
int ret = 0;
- DBusMessage *reply = (DBusMessage *)arg;
- DBusMessageIter iter;
ret = pthread_mutex_lock(&logging_update_mutex);
if (ret) {
}
reply:
+ if (write(sync_pipes[1], &ret, sizeof(ret)) != sizeof(ret))
+ _E("Failed to write the return value of sync thread");
logging_sync_thread = 0;
- dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
-
- if (dbus_message_reply(reply) != RESOURCED_ERROR_NONE)
- _E("Failed to reply sync request");
-
- return NULL;
+ pthread_exit(NULL);
}
-int logging_sync_and_reply(DBusMessage *reply)
+int logging_sync(DBusMessage *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;
}
- if (!pthread_create(&logging_sync_thread, NULL, (void *)logging_sync_thread_main, reply))
+ sync_reply = reply;
+
+ if (!pthread_create(&logging_sync_thread, NULL, (void *)logging_sync_thread_main, NULL))
return 0;
_E("Failed to create logging sync thread");
ecore_timer_del(logging_update_timer);
logging_update_timer = NULL;
+ /* Delete fd handler for sync thread */
+ ecore_main_fd_handler_del(sync_efd);
+
/* Wait thread for working
*
* We can wait thread for finishing work by requesting lock
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;
+ }
+ sync_efd = ecore_main_fd_handler_add(sync_pipes[0], ECORE_FD_READ,
+ (Ecore_Fd_Cb)logging_sync_reply, NULL, NULL, NULL);
+ if (!sync_efd) {
+ _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);
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);