return RESOURCED_ERROR_FAIL;
}
+static int insert_proc_conf_info_in_list(struct proc_conf_info *pci,
+ enum proc_type process_type)
+{
+ if (!pci) {
+ _E("proc_conf_info cannot be NULL");
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+
+ switch (process_type) {
+ case APP_TYPE:
+ fixed_app_list_insert(pci);
+ break;
+ case SERVICE_TYPE:
+ fixed_service_list_insert(pci);
+ break;
+ case PROCESS_TYPE:
+ fixed_process_list_insert(pci);
+ break;
+ default:
+ _E("Unkown process type");
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
+static int init_proc_conf_info(struct proc_conf_info *pci, const char *name)
+{
+ if (!pci || !name) {
+ _E("proc_conf_info and process name cannot be NULL");
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+
+ pci->cpu_sched_info.cpu_sched_type = CPU_SCHED_NONE;
+ pci->cpu_sched_info.cpu_rt_priority = CPU_INIT_PRIO;
+ pci->cpu_sched_info.cpu_nice = CPU_INIT_NICE;
+ pci->watchdog_action = PROC_ACTION_KILL;
+ pci->fail_action = PROC_ACTION_IGNORE;
+ pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
+ pci->oom_score = OOMADJ_APP_MAX + 10;
+ strncpy(pci->name, name, sizeof(pci->name)-1);
+
+ return RESOURCED_ERROR_NONE;
+}
+
+static int register_proc_conf_info(struct proc_conf_info *pci,
+ const char *process_name, enum proc_type process_type)
+{
+ assert(pci);
+
+ if (init_proc_conf_info(pci, process_name) < 0) {
+ free(pci);
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ if (insert_proc_conf_info_in_list(pci, process_type) < 0) {
+ free(pci);
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ return RESOURCED_ERROR_NONE;
+}
+
static int optimizer_config(struct parse_result *result, void *user_data)
{
if (!result)
}
/* common(App or Service or Process) */
- if (!strncmp(result->name, APP_NAME_CONF, strlen(APP_NAME_CONF)+1) ||
- !strncmp(result->name, SERVICE_NAME_CONF, strlen(SERVICE_NAME_CONF)+1) ||
- !strncmp(result->name, OLD_SERVICE_NAME_CONF, strlen(OLD_SERVICE_NAME_CONF)+1) ||
- !strncmp(result->name, PROCESS_NAME_CONF, strlen(PROCESS_NAME_CONF)+1) ||
- !strncmp(result->name, OLD_PROCESS_NAME_CONF, strlen(OLD_PROCESS_NAME_CONF)+1)) {
- pci = fixed_app_and_service_exist_check(result->value,
- result->name[0] == 'A' ? APP_TYPE :
- result->name[0] == 'S' ? SERVICE_TYPE : PROCESS_TYPE);
+ if (!strncmp(result->name, APP_NAME_CONF, strlen(APP_NAME_CONF) + 1)) {
+ pci = fixed_app_and_service_exist_check(result->value, APP_TYPE);
if (pci == NULL) {
pci = (struct proc_conf_info *)calloc(1, sizeof(struct proc_conf_info));
if (pci == NULL) {
- _E("Failed to allocate memory during parsing vendor configurations");
+ _E("Failed to allocate memory during parsing configurations");
return RESOURCED_ERROR_OUT_OF_MEMORY;
}
- pci->cpu_sched_info.cpu_sched_type = CPU_SCHED_NONE;
- pci->cpu_sched_info.cpu_rt_priority = CPU_INIT_PRIO;
- pci->cpu_sched_info.cpu_nice = CPU_INIT_NICE;
- pci->watchdog_action = PROC_ACTION_KILL;
- pci->fail_action = PROC_ACTION_IGNORE;
- pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
- pci->oom_score = OOMADJ_APP_MAX + 10;
- strncpy(pci->name, result->value, sizeof(pci->name)-1);
-
- if (result->name[0] == 'A')
- fixed_app_list_insert(pci);
- else if (result->name[0] == 'S')
- fixed_service_list_insert(pci);
- else
- fixed_process_list_insert(pci);
+
+ return register_proc_conf_info(pci, result->value, APP_TYPE);
+ }
+ } else if (!strncmp(result->name, SERVICE_NAME_CONF, strlen(SERVICE_NAME_CONF) + 1)
+ || !strncmp(result->name, OLD_SERVICE_NAME_CONF,
+ strlen(OLD_SERVICE_NAME_CONF) + 1)) {
+ pci = fixed_app_and_service_exist_check(result->value, SERVICE_TYPE);
+ if (pci == NULL) {
+ pci = (struct proc_conf_info *)calloc(1, sizeof(struct proc_conf_info));
+ if (pci == NULL) {
+ _E("Failed to allocate memory during parsing configurations");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+
+ return register_proc_conf_info(pci, result->value, SERVICE_TYPE);
+ }
+ } else if (!strncmp(result->name, PROCESS_NAME_CONF, strlen(PROCESS_NAME_CONF) + 1)
+ || !strncmp(result->name, OLD_PROCESS_NAME_CONF,
+ strlen(OLD_PROCESS_NAME_CONF) + 1)) {
+ pci = fixed_app_and_service_exist_check(result->value, PROCESS_TYPE);
+ if (pci == NULL) {
+ pci = (struct proc_conf_info *)calloc(1, sizeof(struct proc_conf_info));
+ if (pci == NULL) {
+ _E("Failed to allocate memory during parsing configurations");
+ return RESOURCED_ERROR_OUT_OF_MEMORY;
+ }
+
+ return register_proc_conf_info(pci, result->value, PROCESS_TYPE);
}
}
/* limiter.conf.d */