%define mem_stress OFF
%define swap_module ON
%define timer_slack OFF
-%define vip_agent_module ON
%define memory_eng ON
%define debug_log OFF
-DMEM_STRESS=%{mem_stress} \
-DSWAP_MODULE=%{swap_module} \
-DTIMER_SLACK=%{timer_slack} \
- -DVIP_AGENT=%{vip_agent_module} \
-DMEMORY_ENG=%{memory_eng} \
-DDEBUG_LOG=%{debug_log} \
-DDATAUSAGE_TYPE=NFACCT \
-DMEM_STRESS=%{mem_stress} \
-DSWAP_MODULE=%{swap_module} \
-DTIMER_SLACK=%{timer_slack} \
- -DVIP_AGENT=%{vip_agent_module} \
-DMEMORY_ENG=%{memory_eng} \
-DDEBUG_LOG=%{debug_log} \
-DDATAUSAGE_TYPE=NFACCT \
%if %{?swap_module} == ON
%config %{rd_config_path}/swap.conf
%endif
-%if %{?vip_agent_module} == ON
- %config %{rd_config_path}/vip-process.conf
- %attr(-,root, root) %{_bindir}/vip-release-agent
-%endif
%if %{?timer_slack} == ON
%config %{rd_config_path}/timer-slack.conf
%endif
%if %{?swap_module} == ON
%config %{rd_config_path}/swap.conf
%endif
-%if %{?vip_agent_module} == ON
- %config %{rd_config_path}/vip-process.conf
- %attr(-,root, root) %{_bindir}/vip-release-agent
-%endif
%if %{?timer_slack} == ON
%config %{rd_config_path}/timer-slack.conf
%endif
+++ /dev/null
-/*
- * resourced
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
-*/
-
-#include <ctype.h>
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include "const.h"
-#include "resourced.h"
-#include "trace.h"
-#include "cgroup.h"
-#include "procfs.h"
-#include "macro.h"
-#include "util.h"
-#include "config-parser.h"
-#include "file-helper.h"
-#include "storage-helper.h"
-#include "notifier.h"
-#include "module.h"
-#include "module-data.h"
-#include "vip-process.h"
-
-#define VIP_CONF_FILE RD_CONFIG_FILE(vip-process)
-
-static char **arg_vip_proc_names = NULL;
-static char **arg_vip_systemd_services = NULL;
-
-static int vip_load_config(struct parse_result *result, void *user_data)
-{
- char ***strv;
- char **temp, **templist;
-
- if (strncmp(result->section, "VIP_PROCESS", sizeof("VIP_PROCESS") + 1)) {
- _E("Invalid section name %s", result->section);
- return -1;
- }
-
- if (!result->name || !result->value) {
- _E("lvalue or rvalue is empty");
- return -1;
- }
-
- if (!strncmp(result->name, "VIP_PROC_NAME", sizeof("VIP_PROC_NAME") + 1))
- strv = &arg_vip_proc_names;
- else if (!strncmp(result->name, "VIP_SYSTEMD_SERVICE", sizeof("VIP_SYSTEMD_SERVICE") + 1))
- strv = &arg_vip_systemd_services;
- else {
- _E("Invalid lvalue %s", result->name);
- return -1;
- }
-
- if (str_to_strv(result->value, &temp, WHITESPACE) < 0) {
- _E("Failed to convert str to strv");
- return -1;
- }
-
- if (strv_attach(*strv, temp, &templist, true) < 0) {
- _E("Failed to add %s to VIP list", result->value);
- return -1;
- }
-
- *strv = templist;
- return 0;
-}
-
-static int vip_create_sub_cgroup(const char *name, pid_t pid)
-{
- _cleanup_free_ char *cgroup_name = NULL;
- bool already;
- int r;
-
- assert(name);
- assert(pid);
-
- r = cgroup_make_subdir(VIP_CGROUP, name, &already);
- if (r < 0) {
- _E("failed to create vip sub dir");
- return r;
- }
-
- if (already) {
- _D("PID(%d) is already registered as VIP sub cgroup(%s)",
- pid, name);
- return 0;
- }
-
- r = asprintf(&cgroup_name, "%s/%s", VIP_CGROUP, name);
- if (r < 0) {
- _E("failed to allocate memory");
- return -ENOMEM;
- }
-
- r = cgroup_write_node_uint32(cgroup_name, TASK_FILE_NAME, pid);
- if (r < 0) {
- _E("failed to write pid '%d' to '%s': %m",
- pid, cgroup_name);
- return r;
- }
-
- _D("PID(%d) is registered as VIP sub cgroup(%s)", pid, name);
-
- return 0;
-}
-
-static void vip_create_proc_name_groups(void)
-{
- char **pname = NULL;
- int r;
-
- if (!arg_vip_proc_names)
- return;
-
- FOREACH_STRV(pname, arg_vip_proc_names) {
- pid_t pid = 0;
-
- pid = find_pid_from_cmdline(*pname);
- if (pid > 0) {
- r = vip_create_sub_cgroup(*pname, pid);
- if (r < 0)
- _E("failed to create "
- "sub cgroup of '%s', ignoring", *pname);
- } else
- _D("failed to find pid of name: %s", *pname);
- }
-}
-
-static void vip_create_systemd_service_groups(void)
-{
- char **pname = NULL;
-
- if (!arg_vip_systemd_services)
- return;
-
- FOREACH_STRV(pname, arg_vip_systemd_services) {
- _cleanup_free_ char *err_msg = NULL;
- int r;
- char path[128];
- FILE *fp;
- pid_t pid;
-
- if (snprintf(path, sizeof(path), "%s/systemd/system.slice/%s/tasks",
- DEFAULT_CGROUP, *pname) < 0) {
- _E("Fail to make task path");
- continue;
- }
-
- fp = fopen(path, "r");
- if (!fp) {
- _E("%s is user level service or not running", *pname);
- continue;
- }
-
- if (fscanf(fp, "%d", &pid) < 0) {
- _E("Fail to get pid of %s", *pname);
- fclose(fp);
- continue;
- }
- if (pid > 0) {
- r = vip_create_sub_cgroup(*pname, pid);
- if (r < 0)
- _E("failed to create "
- "sub cgroup of '%s', ignoring", *pname);
- }
-
- fclose(fp);
- }
-}
-
-static int vip_booting_done(void *data)
-{
- vip_create_proc_name_groups();
- vip_create_systemd_service_groups();
-
- return 0;
-}
-
-static int resourced_vip_process_init(void *data)
-{
- _cleanup_close_ int checkfd = -1;
- int r;
-
- r = access(CHECK_RELEASE_PROGRESS, F_OK);
- if (r == 0) {
- r = unlink(CHECK_RELEASE_PROGRESS);
- if (r < 0)
- _E("failed to remove %s: %m", CHECK_RELEASE_PROGRESS);
- }
-
- r = config_parse(VIP_CONF_FILE, vip_load_config, NULL);
- if (r < 0) {
- _E("failed to parse vip config file: %m");
- return RESOURCED_ERROR_FAIL;
- }
-
- if (!arg_vip_proc_names)
- return RESOURCED_ERROR_NONE;
-
- if (!is_mounted(VIP_CGROUP)) {
- r = cgroup_make_subdir(DEFAULT_CGROUP, "vip", NULL);
- if (r < 0) {
- _E("failed to make vip cgroup");
- return RESOURCED_ERROR_FAIL;
- }
-
- r = cgroup_mount_subsystem("vip_cgroup", VIP_CGROUP,
- "none,name=vip_cgroup");
- if (r < 0) {
- _E("failed to mount vip cgroup: %m");
- return RESOURCED_ERROR_FAIL;
- }
-
- r = cgroup_set_release_agent("vip", "/usr/bin/vip-release-agent");
- if (r < 0) {
- _E("failed to set vip release agent: %m");
- return RESOURCED_ERROR_FAIL;
- }
- }
-
- vip_create_proc_name_groups();
- vip_create_systemd_service_groups();
-
- r = register_notifier(RESOURCED_NOTIFIER_BOOTING_DONE,
- vip_booting_done);
- if (r < 0) {
- _E("failed to register notifier BootingDone");
- return RESOURCED_ERROR_FAIL;
- }
-
- return RESOURCED_ERROR_NONE;
-}
-
-static int resourced_vip_process_finalize(void *data)
-{
- strv_free_full(arg_vip_proc_names);
- strv_free_full(arg_vip_systemd_services);
-
- unregister_notifier(RESOURCED_NOTIFIER_BOOTING_DONE, vip_booting_done);
-
- return RESOURCED_ERROR_NONE;
-}
-
-static struct module_ops vip_modules_ops = {
- .priority = MODULE_PRIORITY_NORMAL,
- .name = "vip-process",
- .init = resourced_vip_process_init,
- .exit = resourced_vip_process_finalize,
-};
-
-MODULE_REGISTER(&vip_modules_ops)
+++ /dev/null
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-#include <unistd.h>
-#include <sys/mount.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include "trace.h"
-#include "vip-process.h"
-
-#define TIZEN_DEBUG_MODE_FILE RD_SYS_ETC"/.debugmode"
-#define DUMP_PATH "/usr/bin/all_log_dump.sh"
-#define REBOOT_PATH "/usr/sbin/reboot"
-#define WAIT_TIMEOUT 10
-#define MAX_TIMES 30
-
-static int check_debugenable(void)
-{
- if (access(TIZEN_DEBUG_MODE_FILE, F_OK) == 0)
- return 1;
- else
- return 0;
-}
-
-static int run_exec(char **argv)
-{
- int status = 0, times = 0, wpid;
- pid_t pid = 0;
-
- if (argv == NULL)
- return -3;
-
- pid = fork();
-
- if (pid == -1)
- return -1;
-
- if (pid == 0) {
- setpgid(0, 0);
- if (execv(argv[0], argv) == -1) {
- _E("Error execv: %m.\n");
- _exit(-1);
- }
- _exit(1);
- }
- do {
- wpid = waitpid(pid, &status, WNOHANG);
- if (wpid == 0) {
- if (times < MAX_TIMES) {
- sleep(WAIT_TIMEOUT);
- times++;
- } else {
- _D("timeout!!, kill child process(%s)\n",
- argv[0]);
- kill(pid, SIGKILL);
- }
- }
- } while (wpid == 0 && times <= MAX_TIMES);
- return 0;
-}
-
-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;
-
- dir = opendir(VIP_CGROUP);
- if (!dir) {
- _E("doesn't support cgroup release agent");
- return 0;
- }
- closedir(dir);
-
- _E("call release agent : [%d:%s]\n", argc, argv[1]);
-
- /* check previous process */
- if (access(CHECK_RELEASE_PROGRESS, F_OK) == 0)
- return 0;
-
- /* make tmp file */
- checkfd = creat(CHECK_RELEASE_PROGRESS, 0640);
- if (checkfd < 0) {
- _E("fail to make %s file\n", CHECK_RELEASE_PROGRESS);
- checkfd = 0;
- }
-
- /* unmount cgroup for preventing launching another release-agent */
- _E("systemd service stop");
- umount2("/sys/fs/cgroup", MNT_FORCE |MNT_DETACH);
-
- /* check debug level */
- if (check_debugenable())
- run_exec(dumpargv);
-
- /* clear tmp file */
- if (checkfd) {
- if (unlink(CHECK_RELEASE_PROGRESS) < 0)
- _E("fail to remove %s file\n", CHECK_RELEASE_PROGRESS);
- close(checkfd);
- }
-
- sync();
-
- run_exec(rebootargv);
- return 0;
-}
-