Move calling fork() to main thread 73/284273/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 15 Nov 2022 00:06:39 +0000 (00:06 +0000)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 15 Nov 2022 00:06:39 +0000 (00:06 +0000)
After the previous patchset is applied, dyntranstion feature is not working fine
as below:
+------------------------------------------------------------------------------+
| security_manager_sync_threads_internal(671) > Not all threads synchronized:  |
|     threads left: 15                                                         |
| operator()(1013) > Can't properly setup application threads (Smack label &   |
|     capabilities) for application                                            |
+------------------------------------------------------------------------------+
To avoid the issue, creating a child process for a candidate process is moved to
the main thread.

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

index 3d03c43..1d2eb62 100644 (file)
@@ -944,47 +944,6 @@ static int __candidate_info_create(candidate_process_context_t *cpt,
        return 0;
 }
 
-static gboolean __handle_exec_loader_process(gpointer user_data)
-{
-       candidate_process_context_t *cpt;
-       candidate_info_t *info = user_data;
-
-       _W("Candidate process. type: %d, loader_id: %d, pid: %d",
-                       info->type, info->loader_id, info->pid);
-       if (info->pid > 0) {
-               cpt = __find_slot(info->type, info->loader_id);
-               cpt->last_exec_time = time(NULL);
-               if (cpt->is_hydra) {
-                       cpt->hydra_pid = info->pid;
-               } else {
-                       cpt->pid = info->pid;
-                       __set_live_timer(cpt);
-               }
-
-               _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)",
-                               info->pid, cpt->loader_id, cpt->loader_name);
-               _memory_monitor_reset_timer();
-       }
-
-       __candidate_info_free(info);
-       return G_SOURCE_REMOVE;
-}
-
-static bool __exec_loader_process_cb(void *user_data)
-{
-       candidate_info_t *info = user_data;
-
-       if (info == NULL)
-               return false;
-
-       info->pid = __fork_app_process(__exec_loader_process, info->argv);
-       if (info->pid == -1)
-               _E("Failed to create a child process");
-
-       g_idle_add(__handle_exec_loader_process, info);
-       return false;
-}
-
 static int __prepare_candidate_process(int type, int loader_id)
 {
        candidate_process_context_t *cpt = __find_slot(type, loader_id);
@@ -1002,13 +961,28 @@ static int __prepare_candidate_process(int type, int loader_id)
        if (ret < 0)
                return ret;
 
-       ret = _worker_add_job(__forker, __exec_loader_process_cb, info);
-       if (ret != 0) {
-               _E("_worker_add_job() is failed");
+       info->pid = __fork_app_process(__exec_loader_process, info->argv);
+       if (info->pid == -1) {
+               _E("Failed to create a child process. type: %d", type);
                __candidate_info_free(info);
                return -1;
        }
 
+       _W("Candidate process. type: %d, loader_id: %d, pid: %d",
+                       info->type, info->loader_id, info->pid);
+       cpt = __find_slot(info->type, info->loader_id);
+       cpt->last_exec_time = time(NULL);
+       if (cpt->is_hydra) {
+               cpt->hydra_pid = info->pid;
+       } else {
+               cpt->pid = info->pid;
+               __set_live_timer(cpt);
+       }
+
+       _log_print("[CANDIDATE]", "pid(%7d) | type(%d) | loader(%s)",
+                       info->pid, cpt->loader_id, cpt->loader_name);
+       _memory_monitor_reset_timer();
+       __candidate_info_free(info);
        return 0;
 }