Fix AUL worker 83/257183/5
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Apr 2021 11:46:43 +0000 (20:46 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 21 Apr 2021 05:43:20 +0000 (14:43 +0900)
- Add logs for debugging
- Handle error conditions

Change-Id: I47cf6d17f9ef441ba8aeb2bcbd457981dc0c4883
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul_worker.c

index 66611b4..c39049e 100644 (file)
@@ -105,8 +105,11 @@ static void __destroy_job(gpointer data)
        if (job->tag) {
                context = g_main_context_get_thread_default();
                source = g_main_context_find_source_by_id(context, job->tag);
-               if (source && !g_source_is_destroyed(source))
+               _W("GMainContext(%p), GSource(%p)", context, source);
+               if (source && !g_source_is_destroyed(source)) {
+                       _W("Destroy GSource(%p)", source);
                        g_source_destroy(source);
+               }
        }
 
        free(job->name);
@@ -172,8 +175,22 @@ static gboolean __io_job_handler(GIOChannel *io, GIOCondition condition,
 {
        int fd = g_io_channel_unix_get_fd(io);
        struct job_s *job = (struct job_s *)data;
-       aul_worker_io_job_cb callback = (aul_worker_io_job_cb)job->callback;
+       aul_worker_io_job_cb callback;
+       GSource *source;
+
+       source = g_main_current_source();
+       if (!source || g_source_is_destroyed(source)) {
+               _E("[__JOB__] GSource(%p) is destroyed", source);
+               return G_SOURCE_REMOVE;
+       }
+
+       if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+               _E("[__JOB__] name(%s), condition(%d)", job->name, condition);
+               job->tag = 0;
+               return G_SOURCE_REMOVE;
+       }
 
+       callback = (aul_worker_io_job_cb)job->callback;
        if (callback(fd, job->user_data))
                return G_SOURCE_CONTINUE;
 
@@ -186,7 +203,8 @@ static gboolean __io_job_handler(GIOChannel *io, GIOCondition condition,
 int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
                int fd, aul_worker_io_job_cb callback, void *user_data)
 {
-       GIOCondition cond = G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_ERR;
+       GIOCondition cond = G_IO_IN | G_IO_PRI | G_IO_HUP | G_IO_ERR |
+               G_IO_NVAL;
        struct aul_worker_s *worker = (struct aul_worker_s *)handle;
        struct job_s *job;
        GIOChannel *channel;
@@ -224,6 +242,7 @@ int aul_worker_add_io_job(aul_worker_h handle, const char *job_name,
        g_mutex_lock(&worker->mutex);
        worker->jobs = g_list_append(worker->jobs, job);
        job->tag = g_source_attach(source, worker->context);
+       _W("GMainContext(%p), GSource(%p)", worker->context, source);
        g_mutex_unlock(&worker->mutex);
 
        g_source_unref(source);
@@ -296,6 +315,7 @@ static gpointer __worker_thread_loop(gpointer data)
                return NULL;
        }
 
+       _W("GMainContext(%p)", worker->context);
        g_source_set_callback(source, (GSourceFunc)__notify_cb, worker, NULL);
        g_source_set_priority(source, G_PRIORITY_HIGH);
        g_source_attach(source, worker->context);