summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJusung Son <jusung07.son@samsung.com>2020-02-25 14:21:58 +0900
committerJusung Son <jusung07.son@samsung.com>2020-02-25 17:04:49 +0900
commit1b8896a6ae459b0d8bb507234fbcc58b963b5e2a (patch)
tree7662df048880734cda7f41965edf6915bf6acaa4
parent4507b214c81c33177919383cb31fc3f8e1165aab (diff)
downloadlaunchpad-1b8896a6ae459b0d8bb507234fbcc58b963b5e2a.tar.gz
launchpad-1b8896a6ae459b0d8bb507234fbcc58b963b5e2a.tar.bz2
launchpad-1b8896a6ae459b0d8bb507234fbcc58b963b5e2a.zip
Modify candidate process creation rule for app-defined loader
- Create only one candidate process for each loader Change-Id: If4a17d2574a8068620eda7e8621c39df5dc38ff0 Signed-off-by: Jusung Son <jusung07.son@samsung.com>
-rw-r--r--src/launchpad/inc/loader_info.h2
-rw-r--r--src/launchpad/src/launchpad.c96
-rw-r--r--src/launchpad/src/loader_info.c2
3 files changed, 73 insertions, 27 deletions
diff --git a/src/launchpad/inc/loader_info.h b/src/launchpad/inc/loader_info.h
index 2e703b5..5111519 100644
--- a/src/launchpad/inc/loader_info.h
+++ b/src/launchpad/inc/loader_info.h
@@ -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);
diff --git a/src/launchpad/src/launchpad.c b/src/launchpad/src/launchpad.c
index 3032e22..43540d6 100644
--- a/src/launchpad/src/launchpad.c
+++ b/src/launchpad/src/launchpad.c
@@ -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,
diff --git a/src/launchpad/src/loader_info.c b/src/launchpad/src/loader_info.c
index 375c1fd..2c5c5da 100644
--- a/src/launchpad/src/loader_info.c
+++ b/src/launchpad/src/loader_info.c
@@ -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;