int hydra_fd;
int last_exec_time;
guint timer;
+ char *loader_name;
char *loader_path;
char *loader_extra;
int detection_method;
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,
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)
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");
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,
false,
true, 0);
__set_timer(cpc);
+ free(loader_name);
return lid;
}
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");
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;
}
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,
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);
}
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,
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,
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,
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,