Fix the slot management 06/159906/5
authorHwankyu Jhun <h.jhun@samsung.com>
Mon, 13 Nov 2017 13:59:06 +0000 (22:59 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 14 Nov 2017 00:49:41 +0000 (09:49 +0900)
- Adds the function to reset the slot info
- Fixes the exception about adding the slot timer

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

index 8f51b79..5e66ce0 100755 (executable)
@@ -480,6 +480,19 @@ static void __set_timer(candidate_process_context_t *cpc)
        }
 }
 
+static void __reset_slot(candidate_process_context_t *cpc)
+{
+       if (cpc == NULL)
+               return;
+
+       cpc->send_fd = -1;
+       cpc->prepared = false;
+       cpc->pid = CANDIDATE_NONE;
+       cpc->source = 0;
+       cpc->timer = 0;
+       cpc->idle_checker = 0;
+}
+
 static int __send_launchpad_loader(candidate_process_context_t *cpc,
                app_pkt_t *pkt, const char *app_path, int clifd)
 {
@@ -495,26 +508,17 @@ static int __send_launchpad_loader(candidate_process_context_t *cpc,
                cpc->pid, app_path);
 
        pid = cpc->pid;
-       close(cpc->send_fd);
 
-       cpc->prepared = false;
-       cpc->pid = CANDIDATE_NONE;
-       cpc->send_fd = -1;
-       if (cpc->source > 0) {
+       if (cpc->send_fd > 0)
+               close(cpc->send_fd);
+       if (cpc->source > 0)
                g_source_remove(cpc->source);
-               cpc->source = 0;
-       }
-
-       if (cpc->timer > 0) {
+       if (cpc->timer > 0)
                g_source_remove(cpc->timer);
-               cpc->timer = 0;
-       }
-
-       if (cpc->idle_checker > 0) {
+       if (cpc->idle_checker > 0)
                g_source_remove(cpc->idle_checker);
-               cpc->idle_checker = 0;
-       }
 
+       __reset_slot(cpc);
        __set_timer(cpc);
        return pid;
 }
@@ -981,18 +985,15 @@ static gboolean __handle_loader_client_event(gpointer data)
                SECURE_LOGE("Type %d candidate process was " \
                                "(POLLHUP|POLLNVAL), pid: %d",
                                cpc->type, cpc->pid);
-               close(cpc->send_fd);
-
-               cpc->prepared = false;
-               cpc->pid = CANDIDATE_NONE;
-               cpc->send_fd = -1;
-               cpc->source = 0;
+               if (cpc->send_fd > 0)
+                       close(cpc->send_fd);
                if (cpc->timer > 0)
                        g_source_remove(cpc->timer);
-               cpc->timer = 0;
                if (cpc->idle_checker > 0)
                        g_source_remove(cpc->idle_checker);
-               cpc->idle_checker = 0;
+
+               __reset_slot(cpc);
+
                __prepare_candidate_process(cpc->type, cpc->loader_id);
 
                return G_SOURCE_REMOVE;
@@ -1057,7 +1058,7 @@ static gboolean __handle_sigchild(gpointer data)
                _signal_process_sigchld(&siginfo);
                cpc = __find_slot_from_pid(siginfo.ssi_pid);
                if (cpc != NULL) {
-                       cpc->prepared = false;
+                       __reset_slot(cpc);
                        __prepare_candidate_process(cpc->type, cpc->loader_id);
                }
 
@@ -1082,27 +1083,17 @@ static gboolean __handle_label_monitor(gpointer data)
        while (iter) {
                cpc = (candidate_process_context_t *)iter->data;
                if (cpc->pid > 0) {
-                       if (cpc->source > 0) {
+                       if (cpc->source > 0)
                                g_source_remove(cpc->source);
-                               cpc->source = 0;
-                       }
-
-                       if (cpc->timer > 0) {
+                       if (cpc->timer > 0)
                                g_source_remove(cpc->timer);
-                               cpc->timer = 0;
-                       }
-
-                       if (cpc->idle_checker > 0) {
+                       if (cpc->idle_checker > 0)
                                g_source_remove(cpc->idle_checker);
-                               cpc->idle_checker = 0;
-                       }
-
+                       if (cpc->send_fd > 0)
+                               close(cpc->send_fd);
                        _D("Dispose candidate process %d", cpc->pid);
                        __kill_process(cpc->pid);
-                       close(cpc->send_fd);
-                       cpc->prepared = false;
-                       cpc->pid = CANDIDATE_NONE;
-                       cpc->send_fd = -1;
+                       __reset_slot(cpc);
                        __prepare_candidate_process(cpc->type, cpc->loader_id);
                }
 
@@ -1482,7 +1473,7 @@ static gboolean __handle_launch_event(gpointer data)
                _W("Launch directly %d %p", loader_id, cpc);
                pid = __launch_directly(menu_info->appid, app_path, clifd, kb,
                                menu_info, NULL);
-               if (org_cpc) {
+               if (org_cpc && org_cpc->pid == CANDIDATE_NONE) {
                        if (org_cpc->timer > 0) {
                                g_source_remove(org_cpc->timer);
                                org_cpc->timer = 0;