#include "launchpad_worker.h"
#include "loader_info.h"
#include "perf.h"
+#include "slot_info.h"
#define AUL_PR_NAME 16
#define EXEC_CANDIDATE_EXPIRED 5
static worker_h __cleaner;
static worker_h __forker;
-static candidate_process_context_t *__add_slot(int type, int loader_id,
- 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,
- bool app_exists, bool is_hydra, bool app_check);
+static candidate_process_context_t *__add_slot(slot_info_t *info);
static int __remove_slot(int type, int loader_id);
static int __add_default_slots(void);
static gboolean __handle_idle_checker(gpointer data);
int lid, size;
char *loader_name;
candidate_process_context_t *cpc;
+ slot_info_t slot_info;
_W("cmd add loader");
add_slot_str = bundle_get_val(kb, AUL_K_LOADER_PATH);
caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID);
extra = bundle_get_val(kb, AUL_K_LOADER_EXTRA);
- 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;
- }
+ if (add_slot_str == NULL || caller_pid == NULL)
+ 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), loader_name,
- add_slot_str, extra,
- METHOD_TIMEOUT | METHOD_VISIBILITY,
- METHOD_REQUEST | METHOD_AVAILABLE_MEMORY,
- METHOD_TTL | METHOD_OUT_OF_MEMORY,
- 600,
- 2000,
- DEFAULT_CPU_THRESHOLD_MAX,
- DEFAULT_CPU_THRESHOLD_MIN,
- false,
- true,
- false,
- true);
- __set_timer(cpc);
- free(loader_name);
- return lid;
+ 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;
}
- return -1;
+ snprintf(loader_name, size, "%s%s%d", add_slot_str, caller_pid, lid);
+
+ slot_info.type = LAUNCHPAD_LOADER_TYPE_DYNAMIC;
+ slot_info.loader_id = lid;
+ slot_info.caller_pid = atoi(caller_pid);
+ slot_info.loader_name = loader_name;
+ slot_info.loader_path = add_slot_str;
+ slot_info.loader_extra = extra;
+ slot_info.detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY;
+ slot_info.activation_method = METHOD_REQUEST | METHOD_AVAILABLE_MEMORY;
+ slot_info.deactivation_method = METHOD_TTL | METHOD_OUT_OF_MEMORY;
+ slot_info.ttl = 600;
+ slot_info.timeout_val = 2000;
+ slot_info.threshold_max = DEFAULT_CPU_THRESHOLD_MAX;
+ slot_info.threshold_min = DEFAULT_CPU_THRESHOLD_MIN;
+ slot_info.on_boot = false;
+ slot_info.app_exists = true;
+ slot_info.is_hydra = false;
+ slot_info.app_check = true;
+
+ cpc = __add_slot(&slot_info);
+ free(loader_name);
+ if (cpc == NULL)
+ return -1;
+
+ __set_timer(cpc);
+ return lid;
}
static int __dispatch_cmd_add_app_defined_loader(bundle *kb)
candidate_process_context_t *cpc;
loader_info_t *info;
bundle_raw *extra;
+ slot_info_t slot_info;
_W("cmd add defined loader");
loader_name = bundle_get_val(kb, AUL_K_LOADER_NAME);
if (cpc == NULL) {
lid = __make_loader_id();
bundle_encode(info->extra, &extra, &len);
- 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,
- false,
- true);
-
+ slot_info.type = LAUNCHPAD_LOADER_TYPE_DYNAMIC;
+ slot_info.loader_id = lid;
+ slot_info.caller_pid = 0;
+ slot_info.loader_name = loader_name;
+ slot_info.loader_path = "/usr/bin/app-defined-loader";
+ slot_info.loader_extra = (const char *)extra;
+ slot_info.detection_method = METHOD_TIMEOUT | METHOD_VISIBILITY;
+ slot_info.activation_method =
+ METHOD_REQUEST | METHOD_AVAILABLE_MEMORY;
+ slot_info.deactivation_method =
+ METHOD_TTL | METHOD_OUT_OF_MEMORY;
+ slot_info.ttl = info->ttl;
+ slot_info.timeout_val = 2000;
+ slot_info.threshold_max = DEFAULT_CPU_THRESHOLD_MAX;
+ slot_info.threshold_min = DEFAULT_CPU_THRESHOLD_MIN;
+ slot_info.on_boot = false;
+ slot_info.app_exists = true;
+ slot_info.is_hydra = false;
+ slot_info.app_check = true;
+
+ cpc = __add_slot(&slot_info);
bundle_free_encoded_rawdata(&extra);
if (cpc == NULL) {
_E("cpc is NULL");
free(cpc);
}
-static candidate_process_context_t *__create_slot(int type, int loader_id,
- 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,
- int threshold_max, int threshold_min,
- bool on_boot, bool app_exists, bool is_hydra, bool app_check)
+static candidate_process_context_t *__create_slot(slot_info_t *info)
{
candidate_process_context_t *cpc;
return NULL;
}
- cpc->loader_name = strdup(loader_name);
+ cpc->loader_name = strdup(info->loader_name);
if (cpc->loader_name == NULL) {
- _E("Failed to duplicate loader name(%s)", loader_name);
+ _E("Failed to duplicate loader name(%s)", info->loader_name);
__destroy_slot(cpc);
return NULL;
}
- cpc->loader_path = strdup(loader_path);
+ cpc->loader_path = strdup(info->loader_path);
if (cpc->loader_path == NULL) {
- _E("Failed to duplicate loader path(%s)", loader_path);
+ _E("Failed to duplicate loader path(%s)", info->loader_path);
__destroy_slot(cpc);
return NULL;
}
- cpc->loader_extra = loader_extra ? strdup(loader_extra) : strdup("");
+ cpc->loader_extra =
+ info->loader_extra ? strdup(info->loader_extra) : strdup("");
if (cpc->loader_extra == NULL) {
- _E("Failed to duplicate loader extra(%s)",
- loader_extra ? loader_extra : "null");
+ _E("Failed to duplicate loader extra(%s)", info->loader_extra);
__destroy_slot(cpc);
return NULL;
}
- cpc->type = type;
+ cpc->type = info->type;
cpc->prepared = false;
cpc->pid = CANDIDATE_NONE;
cpc->hydra_pid = HYDRA_NONE;
- cpc->caller_pid = caller_pid;
- cpc->loader_id = loader_id;
+ cpc->caller_pid = info->caller_pid;
+ cpc->loader_id = info->loader_id;
cpc->send_fd = -1;
cpc->hydra_fd = -1;
cpc->last_exec_time = 0;
cpc->timer = 0;
- cpc->detection_method = detection_method;
- cpc->timeout_val = timeout_val;
+ cpc->detection_method = info->detection_method;
+ cpc->timeout_val = info->timeout_val;
cpc->cpu_total_time = 0;
cpc->cpu_idle_time = 0;
- cpc->threshold = threshold_max;
- cpc->threshold_max = threshold_max;
- cpc->threshold_min = threshold_min;
- cpc->on_boot = on_boot;
- cpc->app_exists = app_exists;
+ cpc->threshold = info->threshold_max;
+ cpc->threshold_max = info->threshold_max;
+ cpc->threshold_min = info->threshold_min;
+ cpc->on_boot = info->on_boot;
+ cpc->app_exists = info->app_exists;
cpc->touched = false;
cpc->cur_event = 0;
- cpc->activation_method = activation_method;
- cpc->deactivation_method = deactivation_method;
- cpc->ttl = ttl;
+ cpc->activation_method = info->activation_method;
+ cpc->deactivation_method = info->deactivation_method;
+ cpc->ttl = info->ttl;
cpc->live_timer = 0;
- cpc->is_hydra = is_hydra;
- cpc->app_check = app_check;
+ cpc->is_hydra = info->is_hydra;
+ cpc->app_check = info->app_check;
cpc->score = WIN_SCORE;
cpc->pss = 0;
cpc->cpu_check_count = 0;
return cpc;
}
-static candidate_process_context_t *__add_slot(int type, int loader_id,
- 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,
- int threshold_max, int threshold_min,
- bool on_boot, bool app_exists, bool is_hydra, bool app_check)
+static candidate_process_context_t *__add_slot(slot_info_t *info)
{
candidate_process_context_t *cpc;
int fd;
int hydra_fd;
io_channel_h hydra_channel;
- if (__find_slot(type, loader_id) != NULL)
+ if (info == NULL)
+ return NULL;
+
+ if (__find_slot(info->type, info->loader_id) != NULL)
return NULL;
- cpc = __create_slot(type, loader_id,
- caller_pid, loader_name, loader_path,
- loader_extra, detection_method,
- activation_method, deactivation_method,
- ttl, timeout_val,
- threshold_max, threshold_min,
- on_boot, app_exists, is_hydra, app_check);
+ cpc = __create_slot(info);
if (cpc == NULL)
return NULL;
cpc->channel = channel;
- if (is_hydra) {
+ if (info->is_hydra) {
hydra_fd = __listen_hydra_process(cpc->type, cpc->loader_id);
if (hydra_fd == -1) {
_E("[launchpad] Listening the socket to " \
cpc->hydra_channel = hydra_channel;
}
-
candidate_slot_list = g_list_append(candidate_slot_list, cpc);
return cpc;
bundle_raw *extra = NULL;
int len;
char buf[2048] = {0, };
+ slot_info_t slot_info = {
+ .type = LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset,
+ .loader_name = info->name,
+ .loader_path = info->exe,
+ .threshold_max = info->cpu_threshold_max,
+ .threshold_min = info->cpu_threshold_min,
+ .app_exists = info->app_exists,
+ .is_hydra = info->is_hydra,
+ .app_check = info->app_check,
+ };
if (!strcmp(info->exe, "null")) {
- cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset,
- PAD_LOADER_ID_DIRECT,
- 0, info->name, info->exe, NULL,
- 0, 0, 0, 0, 0,
- info->cpu_threshold_max,
- info->cpu_threshold_min,
- false,
- info->app_exists,
- info->is_hydra,
- info->app_check);
+ slot_info.loader_id = PAD_LOADER_ID_DIRECT;
+
+ cpc = __add_slot(&slot_info);
if (cpc == NULL)
return;
if (info->extra)
bundle_encode(info->extra, &extra, &len);
- cpc = __add_slot(LAUNCHPAD_LOADER_TYPE_USER + user_slot_offset,
- PAD_LOADER_ID_STATIC,
- 0, info->name, info->exe, (char *)extra,
- info->detection_method,
- info->activation_method,
- info->deactivation_method,
- info->ttl,
- info->timeout_val,
- info->cpu_threshold_max,
- info->cpu_threshold_min,
- info->on_boot,
- info->app_exists,
- info->is_hydra,
- info->app_check);
+ slot_info.loader_id = PAD_LOADER_ID_STATIC;
+ slot_info.loader_extra = (const char *)extra;
+ slot_info.detection_method = info->detection_method;
+ slot_info.activation_method = info->activation_method;
+ slot_info.deactivation_method = info->deactivation_method;
+ slot_info.ttl = info->ttl;
+ slot_info.timeout_val = info->timeout_val;
+ slot_info.on_boot = info->on_boot;
+ cpc = __add_slot(&slot_info);
bundle_free_encoded_rawdata(&extra);
if (cpc == NULL)
return;