#include <sys/mount.h>
#define MAKE_NAME(name) CGROUP_##name##_NAME
-#define cgroup_name_cpy(dst, src, length) \
- do { \
- bool success = sizeof(dst) >= length ? true : false; \
- if(success) { \
- strncpy(dst, src, sizeof(dst) - 1); \
- } \
- else { \
- return RESOURCED_ERROR_OUT_OF_MEMORY; \
- } \
- } while(0)
-
-#define cgroup_name_cat(dst, src, length) \
- do { \
- bool success = sizeof(dst) >= strlen(dst) + length ? true : false; \
- if(success) { \
- strncat(dst, src, sizeof(dst) - strlen(dst) - 1); \
- } \
- else { \
- return RESOURCED_ERROR_OUT_OF_MEMORY; \
- } \
- } while(0)
+
/*
* This structure has full hierarchy of cgroups on running system.
int result;
char path[MAX_PATH_LENGTH] = {0, };
- cgroup_name_cpy(path, parentdir, strlen(parentdir) + 1);
+ str_name_cpy(path, parentdir, strlen(parentdir) + 1);
for(int i = CGROUP_VIP; i < CGROUP_END; i++) {
char name[MAX_NAME_LENGTH] = {0, };
if(i == CGROUP_VIP) {
- cgroup_name_cpy(name, MAKE_NAME(VIP), strlen(MAKE_NAME(VIP))+ 1);
+ str_name_cpy(name, MAKE_NAME(VIP), strlen(MAKE_NAME(VIP))+ 1);
}
else if(i == CGROUP_HIGH) {
- cgroup_name_cpy(name, MAKE_NAME(HIGH), strlen(MAKE_NAME(HIGH))+ 1);
+ str_name_cpy(name, MAKE_NAME(HIGH), strlen(MAKE_NAME(HIGH))+ 1);
}
else if(i == CGROUP_MEDIUM) {
- cgroup_name_cpy(name, MAKE_NAME(MEDIUM), strlen(MAKE_NAME(MEDIUM))+ 1);
+ str_name_cpy(name, MAKE_NAME(MEDIUM), strlen(MAKE_NAME(MEDIUM))+ 1);
}
else if(i == CGROUP_LOW) {
- cgroup_name_cpy(name, MAKE_NAME(LOW), strlen(MAKE_NAME(LOW))+ 1);
+ str_name_cpy(name, MAKE_NAME(LOW), strlen(MAKE_NAME(LOW))+ 1);
}
result = cgroup_make_subdir(path, name, NULL);
ret_value_msg_if(result < 0, result, "%s/%s init failed\n", path, name);
- cgroup_name_cat(path, "/", 2);
- cgroup_name_cat(path, name, strlen(name) + 1);
+ str_name_cat(path, "/", 2);
+ str_name_cat(path, name, strlen(name) + 1);
// ../../perprocess
result = cgroup_make_subdir(path, MAKE_NAME(PER_PROCESS), NULL);
}
}
}
+ _D("Success to load %s", file_name);
+ fclose(f);
return 0;
error:
if (ret < 0)
return RESOURCED_ERROR_FAIL;
+ if (resident_pages < shared_pages) {
+ _E("# resident page should be larger than or equal to # shared page");
+ return RESOURCED_ERROR_FAIL;
+ }
+
/*
* The value resident - shared is mostly similar to Uss.
*/
if (!error)
attr->sched_priority = sp.sched_priority;
- if (attr->sched_policy >= 0 && !error)
+ if (attr->sched_policy > 0 && !error)
return RESOURCED_ERROR_NONE;
else
return RESOURCED_ERROR_FAIL;
continue; \
else
-#define FOREACH_STRV(s, l) \
+#define FOREACH_STRV(s, l) \
for ((s) = (l); (s) && *(s); (s)++)
+#define str_name_cpy(dst, src, length) \
+ do { \
+ bool success = sizeof(dst) >= length ? true : false; \
+ if(success) { \
+ strncpy(dst, src, sizeof(dst) - 1); \
+ } \
+ else { \
+ return RESOURCED_ERROR_OUT_OF_MEMORY; \
+ } \
+ } while(0)
+
+#define str_name_cat(dst, src, length) \
+ do { \
+ bool success = sizeof(dst) >= strlen(dst) + length ? true : false; \
+ if(success) { \
+ strncat(dst, src, sizeof(dst) - strlen(dst) - 1); \
+ } \
+ else { \
+ return RESOURCED_ERROR_OUT_OF_MEMORY; \
+ } \
+ } while(0)
+
+
/**
* @desc executes given command and dumps output to a file
* @param argv - command to be executed with parameters
if (pci->mem_action.memory_bytes && pci->mem_action.action) {
struct proc_limit_status pls = {0, };
- pai->memory.memlimit_update_exclude = true;
pls.limit_bytes = pci->mem_action.memory_bytes;
pls.ps.pai = pai;
pls.action = pci->mem_action.action;
return PROC_STATE_SUSPEND;
ui = (struct proc_app_info *)g_slist_nth_data(ppi->app_list, 0);
+ if (!ui)
+ return PROC_STATE_DEFAULT;
+
if (ui->state == PROC_STATE_SUSPEND)
return PROC_STATE_SUSPEND;
pai->state = PROC_STATE_SUSPEND_READY;
int main(int argc, char *argv[])
{
- int checkfd;
char *dumpargv[3] = {DUMP_PATH, "urgent", NULL};
char *rebootargv[4] = {REBOOT_PATH, "silent", NULL, NULL};
DIR *dir = 0;
+ int fd;
_I("[WATCHDOG] Starting process watchdog handler: [%d:%s]", argc, argv[1]);
}
closedir(dir);
- /* check previous process */
- if (access(CHECK_RELEASE_PROGRESS, F_OK) == 0)
+ fd = open(CHECK_RELEASE_PROGRESS, O_RDWR);
+ if (fd > 0) {
+ close(fd);
return 0;
-
- _D("[WATCHDOG] No other release_agent is running.");
-
- /* make tmp file */
- checkfd = creat(CHECK_RELEASE_PROGRESS, 0640);
- if (checkfd < 0) {
- _E("[WATCHDOG] fail to make %s file\n", CHECK_RELEASE_PROGRESS);
- checkfd = 0;
+ }
+ else {
+ _D("[WATCHDOG] No other release_agent is running.");
+
+ /* make tmp file */
+ fd = open(CHECK_RELEASE_PROGRESS, O_CREAT|O_WRONLY|O_TRUNC, 0640);
+ if (fd < 0) {
+ _E("[WATCHDOG] fail to make %s file\n", CHECK_RELEASE_PROGRESS);
+ fd = 0;
+ }
}
/* unmount cgroup for preventing launching another release_agent */
run_exec(dumpargv);
/* clear tmp file */
- if (checkfd) {
- if (unlink(CHECK_RELEASE_PROGRESS) < 0)
+ if (fd) {
+ if (unlinkat(fd, CHECK_RELEASE_PROGRESS, 0) < 0)
_E("[WATCHDOG] fail to remove %s file\n", CHECK_RELEASE_PROGRESS);
- close(checkfd);
+ close(fd);
}
sync();
{
_cleanup_close_ int checkfd = -1;
int r;
+ int fd;
if (proc_watchdog_boot_param_reboot_disabled()) {
proc_watchdog_print_console("Reboot has been disabled, boot param: %s", BOOT_PARAM_PROC_WATCHDOG_REBOOT_DISABLED);
return RESOURCED_ERROR_NONE;
}
- r = access(CHECK_RELEASE_PROGRESS, F_OK);
- if (r == 0) {
- r = unlink(CHECK_RELEASE_PROGRESS);
+ fd = open(CHECK_RELEASE_PROGRESS, O_RDWR);
+ if (fd > 0) {
+ r = unlinkat(fd, CHECK_RELEASE_PROGRESS, 0);
if (r < 0)
_E("[WATCHDOG] failed to remove %s: %m", CHECK_RELEASE_PROGRESS);
+ close(fd);
}
if (!is_mounted(PROC_WATCHDOGCG_PATH)) {
struct proc_limit_status *pls = (struct proc_limit_status *)data;
error = lowmem_limit_set_app(pls->limit_bytes, pls->ps.pai, pls->action);
- if (!error)
+ if (!error && pls->ps.pai)
pls->ps.pai->memory.memlimit_update_exclude = true;
return error;
struct proc_status *ps = (struct proc_status *)data;
- if (ps->pai && ps->pai->memory.memlimit_update_exclude)
+ if (ps->pai == NULL)
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+
+ if (ps->pai->memory.memlimit_update_exclude)
return RESOURCED_ERROR_NONE;
if (mem_service_limit_bytes && mem_service_action != PROC_ACTION_IGNORE) {
struct proc_status *ps = (struct proc_status *)data;
- if (ps->pai && ps->pai->memory.memlimit_update_exclude)
+ if (ps->pai == NULL)
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+
+ if (ps->pai->memory.memlimit_update_exclude)
return RESOURCED_ERROR_NONE;
if (mem_guiapp_limit_bytes && mem_guiapp_action != PROC_ACTION_IGNORE &&
struct proc_status *ps = (struct proc_status *)data;
- if (ps->pai && ps->pai->memory.memlimit_update_exclude)
+ if (ps->pai == NULL)
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+
+ if (ps->pai->memory.memlimit_update_exclude)
return RESOURCED_ERROR_NONE;
lowmem_limit_set_app(mem_bgapp_limit_bytes, ps->pai, mem_bgapp_action);
struct proc_status *ps = (struct proc_status *)data;
+ if (ps->pai == NULL)
+ return RESOURCED_ERROR_INVALID_PARAMETER;
+
if ((mem_guiapp_limit_bytes && ps->pai->type == PROC_TYPE_GUI) ||
(mem_widget_limit_bytes && ps->pai->type == PROC_TYPE_WIDGET))
return lowmem_limit_appwidget(data);
/* Wait on any wake-up call */
ctl = g_async_queue_pop(lmw->queue);
- if (ctl->flags & OOM_DROP)
- LOWMEM_DESTROY_REQUEST(ctl);
+ if (!ctl) {
+ _W("[LMK] ctl structure is NULL");
+ continue;
+ }
- if (!LOWMEM_WORKER_IS_ACTIVE(lmw) || !ctl)
+ if ((ctl->flags & OOM_DROP) || !LOWMEM_WORKER_IS_ACTIVE(lmw)) {
+ LOWMEM_DESTROY_REQUEST(ctl);
break;
+ }
LOWMEM_WORKER_RUN(lmw);
process_again:
static int lowmem_exit(void)
{
- if (strncmp(event_level, MEMCG_DEFAULT_EVENT_LEVEL, sizeof(MEMCG_DEFAULT_EVENT_LEVEL)))
- free(event_level);
-
lowmem_deactivate_worker();
lowmem_limit_exit();
lowmem_system_exit();
c->name = name;
if (cpu_sched_parse_cpuset(c, get_cpucg_conf_value()) < 0) {
- _E("[CPU-SCHED] cpu-sched parse %s coreset: could not parse", name);
return RESOURCED_ERROR_FAIL;
}
static int swap_start_handler(void *data)
{
int ret;
+ const char *path = data;
struct swap_thread_bundle *bundle;
- if (!data) {
- _E("data is NULL");
+ if (!path) {
+ _E("path name is NULL");
return RESOURCED_ERROR_NO_DATA;
}
if (!bundle)
return RESOURCED_ERROR_OUT_OF_MEMORY;
+ str_name_cpy(bundle->msg.path, path, strlen(path) + 1);
bundle->op = SWAP_OP_RECLAIM;
- memcpy(bundle->msg.path, data, sizeof(struct swap_status_msg));
ret = swap_communicate_thread(bundle);
return ret;
}
if (!cgroup_swap)
return;
- cgroup_write_node_uint32(cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE, 1);
+ ret = cgroup_write_node_uint32(cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE, 1);
+ if (ret != RESOURCED_ERROR_NONE)
+ {
+ _E("Failed to write at %s/%s", cgroup_swap->memcg_info->name, MEMCG_MOVE_CHARGE);
+ }
+
snprintf(buf, sizeof(buf), "%s/%s", MEMCG_PATH, MEMCG_FORCE_RECLAIM);
ret = swap_check_node(buf);
if (ret == RESOURCED_ERROR_NONE) {