BUILD_MODULE(${PKGNAME} "daemon" "binary")
-IF("${PROC_USAGE_MODULE}" STREQUAL "ON")
- BUILD_MODULE("${PKGNAME}-proc-usage" "proc-usage" "library")
-ENDIF()
-
IF("${MEMORY_MODULE}" STREQUAL "ON")
BUILD_MODULE("${PKGNAME}-memory" "memory" "library")
ADD_CONFIG("memory")
ENDIF()
+IF("${PROC_MANAGER_MODULE}" STREQUAL "ON")
+ BUILD_MODULE("${PKGNAME}-proc-manager" "proc-manager" "library")
+ ADD_CONFIG("proc-manager")
+ENDIF()
+
+IF("${PROC_USAGE_MODULE}" STREQUAL "ON")
+ BUILD_MODULE("${PKGNAME}-proc-usage" "proc-usage" "library")
+ENDIF()
+
IF("${TEST_MODULE}" STREQUAL "ON")
BUILD_MODULE("${PKGNAME}-test" "test" "library")
ENDIF()
--- /dev/null
+[proc-manager.oom_score_predefined_app]
+# After app is launched, set it's oom_score_adj to SCORE
+# -1000 <= SCORE <= 1000
+# APPID=SCORE
<allow send_destination="org.tizen.resourced"/>
</policy>
+ <policy user="app_fw">
+ <allow send_destinaion="org.tizen.resourced"/>
+ </policy>
+
<policy context="default">
<deny send_destination="org.tizen.resourced"/>
<check send_destination="org.tizen.resourced"
Source102: %{name}.conf
%define memory_module ON
+%define proc_manager_module ON
%define proc_usage_module ON
%define test_module ON
Control memory status to prevent out of memory
%endif
+%if %{proc_manager_module} == ON
+%package proc-manager
+Summary: App life cycle monitor
+Requires: %{name} = %{version}-%{release}
+Requires: %{name}-common = %{version}-%{release}
+%description proc-manager
+Detect changes in application life cycle and take appropriate action
+%endif
+
%if %{proc_usage_module} == ON
%package proc-usage
Summary: Provide process usage information
-DMAJORVER=${MAJORVER} \
-DLIB_DIR=%{_libdir} \
-DCONFIG_INSTALL_DIR=%{config_install_dir} \
- -DPROC_USAGE_MODULE=%{proc_usage_module} \
-DMEMORY_MODULE=%{memory_module} \
- -DTEST_MODULE=%{test_module} \
+ -DPROC_MANAGER_MODULE=%{proc_manager_module} \
+ -DPROC_USAGE_MODULE=%{proc_usage_module} \
+ -DTEST_MODULE=%{test_module}
make %{?jobs:-j%jobs}
%config %{config_install_dir}/memory.conf
%endif
+%if %{proc_manager_module} == ON
+%files proc-manager
+%license LICENSE
+%manifest %{name}-proc-manager.manifest
+%{_libdir}/libresourced-headless-proc-manager.so*
+%config %{config_install_dir}/proc-manager.conf
+%endif
+
%if %{proc_usage_module} == ON
%files proc-usage
%license LICENSE
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * @file proc-manager-common.h
+ * @brief Shared contents in the proc-manager module
+ */
+
+#ifndef __RESOURCED_HEADLESS_PROC_MANAGER_COMMON_H__
+#define __RESOURCED_HEADLESS_PROC_MANAGER_COMMON_H__
+
+#include <macro.h>
+
+/**
+ * @brief Config file related macro
+ */
+#define PROC_MANAGER_CONFIG_FILE_NAME "proc-manager"
+
+#define PROC_MANAGER_GROUP "proc-manager"
+#define PROC_MANAGER_OSA_PREDEFINED_APP_GROUP PROC_MANAGER_GROUP".oom_score_predefined_app"
+
+/**
+ * @details Key(appid), Value(predefined oom_score_adj)
+ */
+GHashTable *proc_manager_osa_predefined_app_list;
+
+#endif /* __RESOURCED_HEADLESS_PROC_MANAGER_COMMON_H__ */
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <gio/gio.h>
+#include <glib.h>
+
+#include <dbus.h>
+#include <event.h>
+#include <log.h>
+#include <macro.h>
+#include <procfs.h>
+
+#include "proc-manager-common.h"
+#include "proc-manager-dbus.h"
+
+/**
+ * @brief D-Bus signal handler for AppLaunch
+ */
+static void proc_manager_dbus_app_launch(GVariant *params)
+{
+ int ret;
+ int *predefined_osa = NULL;
+ pid_t pid = 0;
+ char *appid = NULL;
+ char *pkgid = NULL;
+ char *pkgtype = NULL;
+
+ g_variant_get(params, "(i&s&s&s)", &pid, &appid, &pkgid, &pkgtype);
+ if (pid == 0 || !appid || !pkgid || !pkgtype) {
+ _D("Receive invalid D-Bus message. Ignore it");
+ return;
+ }
+
+ _D("App launched : pid(%u), appid(%s), pkgid(%s), pkgtype(%s)",
+ pid, appid, pkgid, pkgtype);
+
+ predefined_osa = (int *)g_hash_table_lookup(proc_manager_osa_predefined_app_list, (gpointer)appid);
+ if (predefined_osa) {
+ _D("%s is oom_score_adj predefined app. Set to %d", appid, *predefined_osa);
+ ret = procfs_set_oom_score_adj(pid, *predefined_osa);
+ if (ret < 0)
+ _E("Failed to set oom_score_adj for PID %u (%d)", pid, ret);
+ }
+}
+
+static struct dbus_signal proc_manager_dbus_signals[] = {
+ { "AppLaunch", proc_manager_dbus_app_launch },
+};
+
+int proc_manager_dbus_init(void)
+{
+ int ret;
+
+ ret = dbus_register_signals(AUL_DBUS_PATH_APPSTATUS, AUL_DBUS_INTERFACE_APPSTATUS,
+ proc_manager_dbus_signals, ARRAY_SIZE(proc_manager_dbus_signals));
+ if (ret < 0) {
+ _E("Failed to register proc-manager D-Bus signals (%d)", ret);
+ return ret;
+ }
+
+ return 0;
+}
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+/**
+ * @file proc-manager-dbus.h
+ * @brief D-Bus handlers for proc-manager module
+ */
+
+#ifndef __RESOURCED_HEADLESS_PROC_MANAGER_DBUS_H__
+#define __RESOURCED_HEADLESS_PROC_MANAGER_DBUS_H__
+
+#define AUL_DBUS_PATH_APPSTATUS "/Org/Tizen/Aul/AppStatus"
+#define AUL_DBUS_INTERFACE_APPSTATUS "org.tizen.aul.AppStatus"
+
+int proc_manager_dbus_init(void);
+
+#endif /* __RESOURCED_HEADLESS_PROC_MANAGER_DBUS_H__ */
--- /dev/null
+/*
+ * resourced-headless
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * 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 <stdlib.h>
+
+#include <config-parser.h>
+#include <log.h>
+#include <macro.h>
+#include <module.h>
+#include <procfs.h>
+
+#include "proc-manager-common.h"
+#include "proc-manager-dbus.h"
+
+/**
+ * @brief Make a hashtable about oom_score_adj predefined app
+ */
+static void proc_manager_make_predefined_osa_app_list(const char *key, const void *value)
+{
+ int tmp;
+ gint *predefined_osa;
+ gchar *appid;
+
+ tmp = atoi((const char *)value);
+
+ if (tmp < OOM_SCORE_ADJ_MIN || tmp > OOM_SCORE_ADJ_MAX) {
+ _E("%s : NOT included (invalid value %d)", key, tmp);
+ return;
+ }
+
+ appid = g_strndup(key, strlen(key));
+ predefined_osa = g_malloc(sizeof(gint));
+ *predefined_osa = tmp;
+ g_assert(appid && predefined_osa);
+
+ g_hash_table_insert(proc_manager_osa_predefined_app_list, appid, predefined_osa);
+ _D("%s : included (%d)", appid, *predefined_osa);
+}
+
+/**
+ * @brief Read proc-manager config file and configure this module
+ * @return 0 on success, otherwise a negative error value
+ */
+static int proc_manager_read_config(void)
+{
+ int ret;
+
+ /* Read config file */
+ ret = config_parser_open(PROC_MANAGER_CONFIG_FILE_NAME);
+ if (ret < 0) {
+ _E("Failed to open proc-manager config file (%d)", ret);
+ return ret;
+ }
+
+ /* Make predefined oom_score_adj app list */
+ proc_manager_osa_predefined_app_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
+ _D("========== Predefined oom_score_adj app list ==========");
+ config_parser_foreach(PROC_MANAGER_CONFIG_FILE_NAME, PROC_MANAGER_OSA_PREDEFINED_APP_GROUP,
+ proc_manager_make_predefined_osa_app_list);
+ _D("========== Total %d app(s) ==========", g_hash_table_size(proc_manager_osa_predefined_app_list));
+
+ return 0;
+}
+
+static int __INIT__ proc_manager_init(void)
+{
+ int ret;
+
+ ret = proc_manager_read_config();
+ if (ret < 0) {
+ _E("Failed to read config file (%d)", ret);
+ return ret;
+ }
+
+ ret = proc_manager_dbus_init();
+ if (ret < 0) {
+ _E("Failed to initialize proc-manager-dbus (%d)", ret);
+ g_hash_table_destroy(proc_manager_osa_predefined_app_list);
+ return ret;
+ }
+
+ return 0;
+}
+
+static int __EXIT__ proc_manager_exit(void)
+{
+ if (proc_manager_osa_predefined_app_list)
+ g_hash_table_destroy(proc_manager_osa_predefined_app_list);
+
+ config_parser_close(PROC_MANAGER_CONFIG_FILE_NAME);
+
+ return 0;
+}
+
+static struct module proc_manager_module = {
+ .name = "proc-manager",
+ .priority = MODULE_PRIORITY_HIGH,
+ .init = proc_manager_init,
+ .exit = proc_manager_exit,
+ .event_handler = NULL,
+};
+
+MODULE_REGISTER(&proc_manager_module)
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
#define RDHL_DBUS_PATH_PROC RDHL_DBUS_PATH(Process)
#define RDHL_DBUS_INTERFACE_PROC RDHL_DBUS_INTERFACE(process)
-#define AUL_DBUS_PATH_APPSTATUS "org.tizen.aul.AppStatus"
-#define AUL_DBUS_INTERFACE_APPSTATUS "/Org/Tizen/Aul/AppStatus"
-
int proc_usage_dbus_init(void);
#endif /* __RESOURCED_HEADLESS_PROC_USAGE_DBUS_H__ */