if (!result || !user_data)
return RESOURCED_ERROR_INVALID_PARAMETER;
- if (strncmp(result->section, PRIVATE_SECTION, strlen(PRIVATE_SECTION)+1))
- return RESOURCED_ERROR_NONE;
+ if (strncmp(result->section, PRIVATE_SECTION, strlen(PRIVATE_SECTION)+1)) {
+ if (strncmp(result->section, OLD_VIP_GROUP_SECTION, strlen(OLD_VIP_GROUP_SECTION)+1)) {
+ return RESOURCED_ERROR_NONE;
+ }
+ }
- /* common(App or Service) */
- if (!strncmp(result->name, SERVICE_NAME_CONF, strlen(SERVICE_NAME_CONF)+1) ||
- !strncmp(result->name, APP_NAME_CONF, strlen(APP_NAME_CONF)+1)) {
+ /* 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 : SERVICE_TYPE);
+ result->name[0] == 'A' ? APP_TYPE :
+ result->name[0] == 'S' ? SERVICE_TYPE : PROCESS_TYPE);
if (pci == NULL) {
pci = (struct proc_conf_info *)calloc(1, sizeof(struct proc_conf_info));
if (pci == NULL) {
pci->cpu_boosting_level = CPU_BOOSTING_LEVEL_NONE;
strncpy(pci->name, result->value, sizeof(pci->name)-1);
- if (result->name[0] == 'A') {
+ if (result->name[0] == 'A')
fixed_app_list_insert(pci);
- }
- else {
+ else if (result->name[0] == 'S')
fixed_service_list_insert(pci);
- }
+ else
+ fixed_process_list_insert(pci);
}
}
/* limiter.conf.d */
return RESOURCED_ERROR_INVALID_PARAMETER;
}
}
+ /* old style */
+ else if (!strncmp(result->name, OLD_ACTION_ON_FAILURE_NAME_CONF,
+ strlen(OLD_ACTION_ON_FAILURE_NAME_CONF)+1) && *config_type == VIP_CONFIG) {
+ if (!pci) {
+ _E("process configuration information pointer should not be NULL");
+ return RESOURCED_ERROR_FAIL;
+ }
+
+ if (!strncmp(result->value, ACTION_REBOOT_VALUE_CONF,
+ strlen(ACTION_REBOOT_VALUE_CONF) +1)) {
+ pci->fail_action = PROC_ACTION_REBOOT;
+ }
+ else {
+ _E("invalid parameter (%s)", result->value);
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+ }
+ }
else {
_E("Unknown configuration name (%s) and value (%s) on section (%s)",
result->name, result->value, result->section);
/* Load configuration in process.conf */
config_type = PROCESS_CONFIG;
load_per_vendor_configs(PROC_CONF_DIR, vendor_config, &config_type);
+
+ /* old style */
+ config_type = VIP_CONFIG;
+ load_per_vendor_configs(VIP_CONF_DIR, vendor_config, &config_type);
}
void resourced_free_vendor_configs(void)
#define LIMITER_CONF_DIR RD_CONFIG_PATH"/limiter.conf.d"
#define OPTIMIZER_CONF_DIR RD_CONFIG_PATH"/optimizer.conf.d"
#define PROC_CONF_DIR RD_CONFIG_PATH"/process.conf.d"
+/* old style */
+#define VIP_CONF_DIR RD_CONFIG_PATH"/vip-process.d"
/* section name */
/* limiter.conf */
#define MEMORY_APP_STATUS_LIMIT_SECTION "MemoryAppStatusLimit"
#define MEMORY_THROTTLING_SECTION "MemoryThrottling"
#define CPU_THROTTLING_SECTION "CpuThrottling"
+#define OLD_VIP_GROUP_SECTION "VIP_GROUP"
/* optimizer.conf */
#define SWAP_SECTION "MemorySwap"
/* configuration name */
/* limiter.conf */
-#define SERVICE_NAME_CONF "Service"
#define APP_NAME_CONF "App"
+#define SERVICE_NAME_CONF "Service"
+#define OLD_SERVICE_NAME_CONF "SERVICE" /* old style */
+#define PROCESS_NAME_CONF "Process"
+#define OLD_PROCESS_NAME_CONF "PROCESS" /* old style */
#define MEM_CGROUP_NAME_CONF "MemGroup"
#define MEM_LIMIT_ACTION_NAME_CONF "MemLimitAction"
#define ACTION_ON_FAILURE_NAME_CONF "ActionOnFailure"
+#define OLD_ACTION_ON_FAILURE_NAME_CONF "ACTION_ON_FAILURE"
#define WATCHDOG_ACTION_NAME_CONF "WatchdogAction"
#define THROTTLING_LIMIT_NAME_CONF "ThrottlingLimit"
#define MEDIUM_LEVEL_NAME_CONF "MediumLevel"
OPTIMIZER_CONFIG,
MONITOR_CONFIG,
PROCESS_CONFIG,
+ VIP_CONFIG, /* old style */
};
struct parse_result {
enum proc_type {
APP_TYPE,
SERVICE_TYPE,
+ PROCESS_TYPE,
};
struct proc_conf_info {
void fixed_app_and_service_list_exit(void);
void fixed_app_list_insert(struct proc_conf_info *pci);
void fixed_service_list_insert(struct proc_conf_info *pci);
-void fixed_limit_pid_list_insert(pid_t pid, void *value);
-void fixed_limit_pid_list_remove(pid_t pid);
+void fixed_process_list_insert(struct proc_conf_info *pci);
GHashTable* fixed_app_list_get(void);
GHashTable * fixed_service_list_get(void);
+GHashTable * fixed_process_list_get(void);
struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum proc_type proc_type);
enum proc_action fixed_app_and_service_watchdog_action(const char *name, enum proc_type proc_type);
static GHashTable *fixed_app_list;
static GHashTable *fixed_service_list;
+static GHashTable *fixed_process_list;
void fixed_app_and_service_list_init(void)
{
fixed_app_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
fixed_service_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
- g_assert(fixed_app_list && fixed_service_list);
+ fixed_process_list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
+ g_assert(fixed_app_list && fixed_service_list && fixed_process_list);
}
void fixed_app_and_service_list_exit(void)
g_hash_table_destroy(fixed_app_list);
if (fixed_service_list)
g_hash_table_destroy(fixed_service_list);
+ if (fixed_process_list)
+ g_hash_table_destroy(fixed_process_list);
}
void fixed_app_list_insert(struct proc_conf_info *pci)
g_hash_table_insert(fixed_service_list, (gpointer)pci->name, (gpointer)pci);
}
-GHashTable* fixed_service_list_get(void)
+void fixed_process_list_insert(struct proc_conf_info *pci)
{
- return fixed_service_list;
+ g_hash_table_insert(fixed_process_list, (gpointer)pci->name, (gpointer)pci);
}
GHashTable* fixed_app_list_get(void)
return fixed_app_list;
}
+GHashTable* fixed_service_list_get(void)
+{
+ return fixed_service_list;
+}
+
+GHashTable* fixed_process_list_get(void)
+{
+ return fixed_process_list;
+}
+
struct proc_conf_info* fixed_app_and_service_exist_check(const char *name, enum proc_type proc_type)
{
- if (proc_type != APP_TYPE && proc_type != SERVICE_TYPE) {
- _E("Unknown type (we support only service and app types)");
+ if (proc_type != APP_TYPE && proc_type != SERVICE_TYPE && proc_type != PROCESS_TYPE) {
+ _E("Unknown type (we support only app, service, and process types)");
return NULL;
}
return (struct proc_conf_info *)g_hash_table_lookup(fixed_app_list, name);
}
- else {
+ else if (proc_type == SERVICE_TYPE) {
if (g_hash_table_size(fixed_service_list) == 0)
return NULL;
return (struct proc_conf_info *)g_hash_table_lookup(fixed_service_list, name);
}
+ else {
+ if (g_hash_table_size(fixed_process_list) == 0)
+ return NULL;
+
+ return (struct proc_conf_info *)g_hash_table_lookup(fixed_process_list, name);
+ }
}
enum proc_action fixed_app_and_service_watchdog_action(const char *name, enum proc_type proc_type)
fd = open(CHECK_RELEASE_PROGRESS, O_RDWR);
if (fd >= 0) {
+ _D("[WATCHDOG] Release_agent is currently running.");
close(fd);
return 0;
}
return fwrite_uint(RUNTIME_RESOURCED_PID_PATH, (u_int32_t)pid);
}
-static void sig_term_handler(int sig)
+static void sig_int_handler(int sig)
{
- _E("sigterm or sigint received");
+ _E("signal = %d is received", sig);
resourced_quit_mainloop();
}
+static void sig_term_handler(int sig, siginfo_t *siginfo, void *context)
+{
+ char appname[PROC_NAME_MAX];
+ pid_t sender_pid = siginfo->si_pid;
+
+ proc_get_cmdline(sender_pid, appname, sizeof(appname));
+ _D("signal = %d sender pid = %d (%s)", sig, sender_pid, appname);
+ _I("Do not quit resourced");
+// resourced_quit_mainloop();
+}
+
static void add_signal_handler(void)
{
- signal(SIGTERM, sig_term_handler);
- signal(SIGINT, sig_term_handler);
+ struct sigaction sig_act;
+
+ sig_act.sa_sigaction = sig_term_handler;
+ sig_act.sa_flags = 0;
+ sig_act.sa_flags |= SA_SIGINFO;
+ sigaction(SIGTERM, &sig_act, NULL);
+// signal(SIGTERM, sig_term_handler);
+ signal(SIGINT, sig_int_handler);
}
GMainLoop *get_main_loop(void)
g_source_attach(shared_data->darg->mainloop_quit, NULL);
}
-int fixed_service_list_init(void *data)
+int fixed_list_init(enum proc_type proc_type)
{
int error;
gpointer key;
GHashTableIter iter;
struct sched_attr attr;
- g_hash_table_iter_init(&iter, fixed_service_list_get());
+ if (proc_type == SERVICE_TYPE)
+ g_hash_table_iter_init(&iter, fixed_service_list_get());
+ else if (proc_type == PROCESS_TYPE)
+ g_hash_table_iter_init(&iter, fixed_process_list_get());
+ else {
+ _E("Unknown proc_type = %d", proc_type);
+ return RESOURCED_ERROR_FAIL;
+ }
while (g_hash_table_iter_next(&iter, &key, &value)) {
struct proc_conf_info *pci = (struct proc_conf_info *)value;
}
if (strncmp(pci->name, name, strlen(name) +1)) {
- _E("key (%s) should be same with service name (%s)", name, pci->name);
+ _E("key (%s) should be same with name (%s)", name, pci->name);
continue;
}
- variant = systemd_get_service_property(pci->name, "ExecMainPID");
- if (!g_variant_get_safe(variant, "u", &pid))
- _E("Failed to get pid of a service (%s)", pci->name);
+ if (proc_type == SERVICE_TYPE) {
+ variant = systemd_get_service_property(pci->name, "ExecMainPID");
+ if (!g_variant_get_safe(variant, "u", &pid))
+ _E("Failed to get pid of a service (%s)", pci->name);
+ }
+ else
+ pid = find_pid_from_cmdline(pci->name);
if (pid <= 0) {
_W("name (%s) pid should be larger than 0", pci->name);
pci->pid = pid;
- /* Put a system service into (cpu) throttling group */
+ /* Put a system service or process into (cpu) throttling group */
if (pci->cpu_throttling_enable) {
struct proc_status ps = {0, };
ps.pid = pid;
pci->cpu_sched_info.cpu_nice <= CPU_MAX_NICE) {
attr.sched_nice = pci->cpu_sched_info.cpu_nice;
}
- else {
+ else
attr.sched_nice = CPU_INIT_NICE;
- }
if (pci->cpu_sched_info.cpu_rt_priority >= CPU_MIN_PRIO &&
pci->cpu_sched_info.cpu_rt_priority <= CPU_MAX_PRIO) {
attr.sched_priority = pci->cpu_sched_info.cpu_rt_priority;
}
- else {
+ else
attr.sched_priority = CPU_INIT_PRIO;
- }
switch (pci->cpu_sched_info.cpu_sched_type) {
case CPU_SCHED_NONE:
_I("[CPU-SCHED] %s's priority = %d", pci->name, attr.sched_priority);
skip_scheduler_update:
- /* Put a system service into (cpu) boosting group */
+ /* Put a system service or process into (cpu) boosting group */
if (pci->cpu_boosting_level != CPU_BOOSTING_LEVEL_NONE) {
struct proc_status ps = {0, };
ps.pid = pid;
resourced_notify(RESOURCED_NOTIFIER_BOOSTING_RESOURCE, &ps);
}
- /* register a notification when this service is released */
+ /* register a notification when this service or process is released */
switch (pci->fail_action) {
case PROC_ACTION_REBOOT:
proc_watchdog_booting_done(pci->name, pid);
_W("[WATCHDOG] Currently we support only REBOOT when a service is released");
}
- /* Put a system service into (memory) throttling group */
+ /* Put a system service or process into (memory) throttling group */
if (pci->memory_throttling_enable)
cgroup_write_pid_fullpath(MEMCG_THROTTLING_PATH, pid);
- /* register a notification when this service memory is over a threshold */
+ /* register a notification when this service or process memory is over a threshold */
if (pci->mem_action.memory_bytes && pci->mem_action.action) {
struct proc_limit_status pls = {0, };
return RESOURCED_ERROR_NONE;
}
+int fixed_service_and_process_list_init(void *data)
+{
+ fixed_list_init(SERVICE_TYPE);
+ fixed_list_init(PROCESS_TYPE);
+
+ return RESOURCED_ERROR_NONE;
+}
GMainLoop *get_main_loop(void);
void resourced_quit_mainloop(void);
-int fixed_service_list_init(void *data);
+int fixed_service_and_process_list_init(void *data);
struct counter_arg;
* ex) /etc/resourced/xxx.d/yyy.conf
*/
resourced_parse_vendor_configs();
- register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_list_init);
+ register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
if (resourced_restarted()) {
_I("Relaunched. Start to initialize and restore");
g_main_loop_run(mainloop);
g_main_loop_quit(mainloop);
- unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_list_init);
+ unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, fixed_service_and_process_list_init);
/* free all allocated memory to store configuration information */
resourced_free_vendor_configs();