4 * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <sys/types.h>
34 #include "resourced.h"
36 #include "proc-main.h"
38 #include "proc-process.h"
40 #include "config-parser.h"
41 #include "file-helper.h"
43 #include "module-data.h"
44 #include "vip-process.h"
46 #define VIP_CONF_FILE "/etc/resourced/vip-process.conf"
47 #define VIP_CONF_SECTION "VIP_PROCESS"
48 #define VIP_CONF_NAME "VIP_PROC_NAME"
49 #define AGENT_PATH "/usr/bin/vip-release-agent"
50 #define VIP_RELEASE_AGENT "/release_agent"
51 #define VIP_NOTIFY_ON_RELEASE "/notify_on_release"
54 static int load_vip_config(struct parse_result *result, void *user_data)
57 char cgroup_name[MAX_NAME_LENGTH];
61 if (strcmp(result->section, VIP_CONF_SECTION))
62 return RESOURCED_ERROR_NONE;
64 if (!strcmp(result->name, VIP_CONF_NAME)) {
66 /* 2. decrease oom score adj for excepting it in oom candidate list */
68 pid = find_pid_from_cmdline(result->value);
70 make_cgroup_subdir(VIP_CGROUP, result->value, NULL);
71 snprintf(cgroup_name, sizeof(cgroup_name), "%s/%s",
72 VIP_CGROUP, result->value);
73 cgroup_write_node(cgroup_name, TASK_FILE_NAME, pid);
76 return RESOURCED_ERROR_NONE;
79 static int resourced_vip_process_init(void *data)
82 checkfd = open(CHECK_RELEASE_PROGRESS, O_RDONLY, 0666);
85 if (unlink(CHECK_RELEASE_PROGRESS) < 0)
86 _E("fail to remove %s file\n", CHECK_RELEASE_PROGRESS);
89 make_cgroup_subdir(DEFAULT_CGROUP, "vip", NULL);
90 mount_cgroup_subsystem("vip_cgroup", VIP_CGROUP, "none,name=vip_cgroup");
91 cgroup_write_node_str(VIP_CGROUP, VIP_RELEASE_AGENT, AGENT_PATH);
92 cgroup_write_node(VIP_CGROUP, VIP_NOTIFY_ON_RELEASE , 1);
93 config_parse(VIP_CONF_FILE, load_vip_config, NULL);
94 return RESOURCED_ERROR_NONE;
97 static int resourced_vip_process_finalize(void *data)
99 return RESOURCED_ERROR_NONE;
102 static struct module_ops vip_modules_ops = {
103 .priority = MODULE_PRIORITY_NORMAL,
104 .name = "vip-process",
105 .init = resourced_vip_process_init,
106 .exit = resourced_vip_process_finalize,
109 MODULE_REGISTER(&vip_modules_ops)