#include "config-parser.h"
#include "notifier.h"
#include "userinfo-list.h"
-#include "fd-handler.h"
#define LOGGING_BUF_MAX 1024
#define LOGGING_PTIORITY 20
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)
{
}
}
-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;
}
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);
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;
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
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);
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);