Fix a bug about loader creation 81/183681/3
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 10 Jul 2018 03:09:00 +0000 (12:09 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 10 Jul 2018 04:32:41 +0000 (13:32 +0900)
Even though the loader processs is running, a new loader process
is started by the timeout handler.
To prevent duplication, this patch adds exceptions.

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

index 1afa58a..c42fb33 100755 (executable)
@@ -179,6 +179,11 @@ static gboolean __handle_queuing_slots(gpointer data)
                return G_SOURCE_CONTINUE;
        }
 
+       if (cpc->timer) {
+               g_source_remove(cpc->timer);
+               cpc->timer = 0;
+       }
+
        _get_cpu_idle(&total, &idle);
        cpc->cpu_idle_time = idle;
        cpc->cpu_total_time = total;
@@ -191,16 +196,45 @@ static gboolean __handle_queuing_slots(gpointer data)
        return G_SOURCE_CONTINUE;
 }
 
-static int __sequencer_add_slot(candidate_process_context_t *cpc)
+static bool __sequencer_slot_is_running(candidate_process_context_t *cpc)
+{
+       GSource *source;
+       guint source_id;
+
+       source = g_main_context_find_source_by_funcs_user_data(NULL,
+                       (GSourceFuncs *)__handle_idle_checker, (gpointer)cpc);
+       if (source) {
+               source_id = g_source_get_id(source);
+               if (source_id != 0 && source_id == __sequencer.idle_checker)
+                       return true;
+       }
+
+       return false;
+}
+
+static bool __sequencer_slot_exist(candidate_process_context_t *cpc)
 {
        GList *found;
 
        found = g_queue_find(__sequencer.queue, cpc);
-       if (found) {
+       if (found)
+               return true;
+
+       return false;
+}
+
+static int __sequencer_add_slot(candidate_process_context_t *cpc)
+{
+       if (__sequencer_slot_exist(cpc)) {
                _W("Already exists");
                return -1;
        }
 
+       if (__sequencer_slot_is_running(cpc)) {
+               _W("slot(%d) is running", cpc->type);
+               return -1;
+       }
+
        g_queue_push_tail(__sequencer.queue, cpc);
 
        return 0;
@@ -619,6 +653,11 @@ static gboolean __handle_timeout_event(gpointer user_data)
        cpc = (candidate_process_context_t *)user_data;
        cpc->timer = 0;
 
+       if (cpc->pid != CANDIDATE_NONE) {
+               _W("Candidate(%d) process(%d) is running", cpc->type, cpc->pid);
+               return G_SOURCE_REMOVE;
+       }
+
        __sequencer_add_slot(cpc);
        __sequencer_run();
        return G_SOURCE_REMOVE;
@@ -1778,7 +1817,8 @@ static gboolean __handle_launch_event(gpointer data)
                pid = __launch_directly(menu_info->appid, app_path, clifd, kb,
                                menu_info, NULL);
                if (org_cpc && org_cpc->app_exists &&
-                               org_cpc->pid == CANDIDATE_NONE) {
+                               org_cpc->pid == CANDIDATE_NONE &&
+                               !__sequencer_slot_exist(org_cpc)) {
                        if (org_cpc->timer > 0) {
                                g_source_remove(org_cpc->timer);
                                org_cpc->timer = 0;