Modify candidate process creation rule for app-defined loader 59/225859/2
authorJusung Son <jusung07.son@samsung.com>
Tue, 25 Feb 2020 05:21:58 +0000 (14:21 +0900)
committerJusung Son <jusung07.son@samsung.com>
Tue, 25 Feb 2020 08:04:49 +0000 (17:04 +0900)
 - Create only one candidate process for each loader

Change-Id: If4a17d2574a8068620eda7e8621c39df5dc38ff0
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/launchpad/inc/loader_info.h
src/launchpad/src/launchpad.c
src/launchpad/src/loader_info.c

index 2e703b5214194785f8aff3179e832e8f149815fc..5111519e7385c7d9b1415e9554b08654436f1e59 100644 (file)
@@ -64,7 +64,7 @@ void _loader_info_dispose(GList *info);
 int _loader_info_find_type(GList *info, const char *app_type, bool hwacc);
 int _loader_info_find_type_by_loader_name(GList *info, const char *loader_name);
 const char* _loader_info_find_loader_path_by_loader_name(GList *info, const char *loader_name);
-const loader_info_t* _loader_info_find_loader_by_loader_name(GList *info, const char *loader_name);
+loader_info_t* _loader_info_find_loader_by_loader_name(GList *info, const char *loader_name);
 int *_loader_get_alternative_types(GList *info, int type, int *len);
 int _loader_info_foreach(GList *info, loader_info_foreach_cb callback,
                void *data);
index 3032e2283df9cddace18c3404dede0464e114781..43540d667492a4a76d0a50faa9a9aeeac46b22a3 100644 (file)
@@ -96,6 +96,7 @@ typedef struct {
        int hydra_fd;
        int last_exec_time;
        guint timer;
+       char *loader_name;
        char *loader_path;
        char *loader_extra;
        int detection_method;
@@ -172,7 +173,8 @@ static io_channel_h __sigchild_channel;
 static io_channel_h __launchpad_channel;
 
 static candidate_process_context_t *__add_slot(int type, int loader_id,
-               int caller_pid, const char *loader_path, const char *extra,
+               int caller_pid, const char *loader_name,
+               const char *loader_path, const char *extra,
                int detection_method, int activation_method,
                int deactivation_method, unsigned int ttl, int timeout_val,
                int threshold_max, int threshold_min, bool on_boot,
@@ -423,6 +425,22 @@ static candidate_process_context_t *__find_slot_from_loader_id(int id)
        return NULL;
 }
 
+static candidate_process_context_t *__find_slot_from_loader_name(const char *loader_name)
+{
+       candidate_process_context_t *cpc;
+       GList *iter = candidate_slot_list;
+
+       while (iter) {
+               cpc = (candidate_process_context_t *)iter->data;
+               if (strcmp(cpc->loader_name, loader_name) == 0)
+                       return cpc;
+
+               iter = g_list_next(iter);
+       }
+
+       return NULL;
+}
+
 static candidate_process_context_t *__find_slot(int type, int loader_id)
 {
        if (type == LAUNCHPAD_LOADER_TYPE_DYNAMIC)
@@ -1679,7 +1697,8 @@ static int __dispatch_cmd_add_loader(bundle *kb)
        const char *add_slot_str = NULL;
        const char *caller_pid = NULL;
        const char *extra;
-       int lid;
+       int lid, size;
+       char *loader_name;
        candidate_process_context_t *cpc;
 
        _W("cmd add loader");
@@ -1689,8 +1708,18 @@ static int __dispatch_cmd_add_loader(bundle *kb)
 
        if (add_slot_str && caller_pid) {
                lid = __make_loader_id();
+
+               size = snprintf(0, 0, "%s%s%d", add_slot_str, caller_pid, lid);
+               loader_name = (char *)malloc(size + 1);
+               if (loader_name == NULL) {
+                       _E("Out of memory");
+                       return -1;
+               }
+
+               snprintf(loader_name, size, "%s%s%d", add_slot_str, caller_pid, lid);
+
                cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid,
-                               atoi(caller_pid),
+                               atoi(caller_pid), loader_name,
                                add_slot_str, extra,
                                METHOD_TIMEOUT | METHOD_VISIBILITY,
                                METHOD_REQUEST | METHOD_AVAILABLE_MEMORY,
@@ -1702,6 +1731,7 @@ static int __dispatch_cmd_add_loader(bundle *kb)
                                false,
                                true, 0);
                __set_timer(cpc);
+               free(loader_name);
                return lid;
        }
 
@@ -1713,7 +1743,7 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb)
        const char *loader_name;
        int lid, len;
        candidate_process_context_t *cpc;
-       const loader_info_t *info;
+       loader_info_t *info;
        bundle_raw *extra;
 
        _W("cmd add defined loader");
@@ -1733,25 +1763,31 @@ static int __dispatch_cmd_add_app_defined_loader(bundle *kb)
 
        bundle_encode(info->extra, &extra, &len);
 
-       lid = __make_loader_id();
-       cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0,
-                       "/usr/bin/app-defined-loader", (const char *)extra,
-                       METHOD_TIMEOUT | METHOD_VISIBILITY,
-                       METHOD_REQUEST | METHOD_AVAILABLE_MEMORY,
-                       METHOD_TTL | METHOD_OUT_OF_MEMORY,
-                       info->ttl,
-                       2000,
-                       DEFAULT_CPU_THRESHOLD_MAX,
-                       DEFAULT_CPU_THRESHOLD_MIN,
-                       false,
-                       true, 0);
+       cpc = __find_slot_from_loader_name(loader_name);
        if (cpc == NULL) {
-               _E("cpc is NULL");
-               bundle_free_encoded_rawdata(&extra);
-               return -ENOMEM;
+               lid = __make_loader_id();
+               cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid, 0,
+                               loader_name, "/usr/bin/app-defined-loader", (const char *)extra,
+                               METHOD_TIMEOUT | METHOD_VISIBILITY,
+                               METHOD_REQUEST | METHOD_AVAILABLE_MEMORY,
+                               METHOD_TTL | METHOD_OUT_OF_MEMORY,
+                               info->ttl,
+                               2000,
+                               DEFAULT_CPU_THRESHOLD_MAX,
+                               DEFAULT_CPU_THRESHOLD_MIN,
+                               false,
+                               true, 0);
+               if (cpc == NULL) {
+                       _E("cpc is NULL");
+                       bundle_free_encoded_rawdata(&extra);
+                       return -ENOMEM;
+               }
+       } else {
+               lid = cpc->loader_id;
        }
 
-       __prepare_candidate_process(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid);
+       if (cpc->pid == CANDIDATE_NONE)
+               __prepare_candidate_process(LAUNCHPAD_LOADER_TYPE_DYNAMIC, lid);
 
        return lid;
 }
@@ -2184,11 +2220,14 @@ static void __destroy_slot(candidate_process_context_t *cpc)
        if (cpc->loader_path)
                free(cpc->loader_path);
 
+       if (cpc->loader_name)
+               free(cpc->loader_name);
+
        free(cpc);
 }
 
 static candidate_process_context_t *__create_slot(int type, int loader_id,
-               int caller_pid, const char *loader_path,
+               int caller_pid, const char *loader_name, const char *loader_path,
                const char *loader_extra, int detection_method,
                int activation_method, int deactivation_method,
                unsigned int ttl, int timeout_val,
@@ -2203,6 +2242,13 @@ static candidate_process_context_t *__create_slot(int type, int loader_id,
                return NULL;
        }
 
+       cpc->loader_name = strdup(loader_name);
+       if (cpc->loader_name == NULL) {
+               _E("Failed to duplicate loader name(%s)", loader_name);
+               __destroy_slot(cpc);
+               return NULL;
+       }
+
        cpc->loader_path = strdup(loader_path);
        if (cpc->loader_path == NULL) {
                _E("Failed to duplicate loader path(%s)", loader_path);
@@ -2257,7 +2303,7 @@ static candidate_process_context_t *__create_slot(int type, int loader_id,
 }
 
 static candidate_process_context_t *__add_slot(int type, int loader_id,
-               int caller_pid, const char *loader_path,
+               int caller_pid, const char *loader_name, const char *loader_path,
                const char *loader_extra, int detection_method,
                int activation_method, int deactivation_method,
                unsigned int ttl, int timeout_val,
@@ -2274,7 +2320,7 @@ static candidate_process_context_t *__add_slot(int type, int loader_id,
                return NULL;
 
        cpc = __create_slot(type, loader_id,
-                       caller_pid, loader_path,
+                       caller_pid, loader_name, loader_path,
                        loader_extra, detection_method,
                        activation_method, deactivation_method,
                        ttl, timeout_val,
@@ -2555,7 +2601,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
        if (!strcmp(info->exe, "null")) {
                cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset,
                                PAD_LOADER_ID_DIRECT,
-                               0, info->exe, NULL,
+                               0, info->name, info->exe, NULL,
                                0, 0, 0, 0, 0,
                                info->cpu_threshold_max,
                                info->cpu_threshold_min,
@@ -2578,7 +2624,7 @@ static void __add_slot_from_info(gpointer data, gpointer user_data)
 
                cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset,
                                PAD_LOADER_ID_STATIC,
-                               0, info->exe, (char *)extra,
+                               0, info->name, info->exe, (char *)extra,
                                info->detection_method,
                                info->activation_method,
                                info->deactivation_method,
index 375c1fdde8daf494d16c598c85d99e4d2e218e86..2c5c5dad906d698331e73c9e0abde7762d1fe4a1 100644 (file)
@@ -385,7 +385,7 @@ const char* _loader_info_find_loader_path_by_loader_name(GList *list, const char
        return info->exe;
 }
 
-const loader_info_t* _loader_info_find_loader_by_loader_name(GList *list, const char *loader_name)
+loader_info_t* _loader_info_find_loader_by_loader_name(GList *list, const char *loader_name)
 {
        GList *cur;
        loader_info_t *info;