From: hyunuktak Date: Wed, 30 May 2018 07:24:44 +0000 (+0900) Subject: Load procfs on booting time X-Git-Tag: accepted/tizen/unified/20180612.044129~2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fstc-manager.git;a=commitdiff_plain;h=941d2b993313976d42a0908980024ca5a4b428ac Load procfs on booting time Change-Id: If68c6428cfb364aff9fbfd2a904ff6fee82a6a4d Signed-off-by: hyunuktak --- diff --git a/include/stc-manager-plugin-procfs.h b/include/stc-manager-plugin-procfs.h old mode 100644 new mode 100755 index 83e7332..9e7b565 --- a/include/stc-manager-plugin-procfs.h +++ b/include/stc-manager-plugin-procfs.h @@ -24,6 +24,7 @@ int stc_plugin_procfs_init(void); int stc_plugin_procfs_deinit(void); +stc_error_e stc_plugin_procfs_load_pid(void); stc_error_e stc_plugin_procfs_app_status_changed(stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type); diff --git a/packaging/stc-manager.spec b/packaging/stc-manager.spec index 7d6decf..52b858d 100644 --- a/packaging/stc-manager.spec +++ b/packaging/stc-manager.spec @@ -1,6 +1,6 @@ Name: stc-manager Summary: STC(Smart Traffic Control) manager -Version: 0.0.66 +Version: 0.0.67 Release: 0 Group: Network & Connectivity/Other License: Apache-2.0 diff --git a/plugin/procfs/include/stc-plugin-procfs.h b/plugin/procfs/include/stc-plugin-procfs.h old mode 100644 new mode 100755 index 3a02bfe..7375041 --- a/plugin/procfs/include/stc-plugin-procfs.h +++ b/plugin/procfs/include/stc-plugin-procfs.h @@ -24,6 +24,7 @@ typedef struct { int (*initialize_plugin) (void); int (*deinitialize_plugin) (void); + int (*procfs_load) (void); int (*procfs_status_changed) (stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type); } stc_plugin_procfs_s; @@ -31,6 +32,7 @@ typedef struct { int stc_plugin_procfs_initialize(void); int stc_plugin_procfs_deinitialize(void); +int stc_plugin_procfs_load(void); stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type); diff --git a/plugin/procfs/stc-plugin-procfs.c b/plugin/procfs/stc-plugin-procfs.c old mode 100644 new mode 100755 index 36b8f78..80cf9b1 --- a/plugin/procfs/stc-plugin-procfs.c +++ b/plugin/procfs/stc-plugin-procfs.c @@ -523,6 +523,37 @@ static int __unsubscribe_proc_events(void) return 0; } +static bool __process_pid_cb(pid_t pid, void *user_data) +{ + char cmdline[PROC_NAME_MAX] = {0, }; + char status[PROC_STATUS_CNT][PROC_BUF_MAX]; + + memset(status, 0x0, sizeof(status)); + + if (STC_ERROR_NONE == proc_get_cmdline(pid, cmdline) && + STC_ERROR_NONE == proc_get_status(pid, status)) { + + if (__check_excn(cmdline)) + return true; + + unsigned int i; + proc_key_s key; + proc_value_s value; + + memset(&key, 0x0, sizeof(proc_key_s)); + memset(&value, 0x0, sizeof(proc_value_s)); + + key.pid = pid; + for (i = 0; i < PROC_STATUS_CNT; ++i) + g_strlcpy(value.status[i], status[i], sizeof(value.status[i])); + g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline)); + + __proc_tree_add(&key, &value); + } + + return true; +} + int stc_plugin_procfs_initialize(void) { __STC_LOG_FUNC_ENTER__; @@ -558,6 +589,16 @@ int stc_plugin_procfs_deinitialize(void) return STC_ERROR_NONE; } +stc_error_e stc_plugin_procfs_load(void) +{ + __STC_LOG_FUNC_ENTER__; + + proc_foreach_pid(__process_pid_cb, NULL); + + __STC_LOG_FUNC_EXIT__; + return STC_ERROR_NONE; +} + stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, const gchar *pkg_id, @@ -682,6 +723,8 @@ API stc_plugin_procfs_s stc_plugin_procfs = { stc_plugin_procfs_initialize, .deinitialize_plugin = stc_plugin_procfs_deinitialize, + .procfs_load = + stc_plugin_procfs_load, .procfs_status_changed = stc_plugin_procfs_status_changed }; diff --git a/src/helper/helper-procfs.c b/src/helper/helper-procfs.c old mode 100644 new mode 100755 index 020987d..8cd0461 --- a/src/helper/helper-procfs.c +++ b/src/helper/helper-procfs.c @@ -118,6 +118,35 @@ pid_t find_pid_from_cmdline(char *cmdline) return foundpid; } +API void proc_foreach_pid(proc_pid_cb cb, void *user_data) +{ + pid_t pid = -1; + int ret = 0; + DIR *dp; + struct dirent *dentry; + + dp = opendir("/proc"); + if (!dp) { + STC_LOGE("failed to open /proc"); + return; + } + + while ((dentry = readdir(dp)) != NULL) { + if (!isdigit(dentry->d_name[0])) + continue; + + pid = atoi(dentry->d_name); + if (!pid) + continue; + + ret = cb(pid, user_data); + if (ret == false) + break; + } + + closedir(dp); +} + int proc_get_label(pid_t pid, char *label) { char buf[PROC_BUF_MAX]; diff --git a/src/helper/helper-procfs.h b/src/helper/helper-procfs.h old mode 100644 new mode 100755 index 55c6a03..26839c6 --- a/src/helper/helper-procfs.h +++ b/src/helper/helper-procfs.h @@ -22,6 +22,8 @@ #define PROC_BUF_MAX 64 +typedef bool (*proc_pid_cb)(pid_t pid, void *user_data); + /** * @desc get command line from /proc/{pid}/cmdline * @return negative value if error @@ -36,6 +38,11 @@ int proc_get_cmdline(pid_t pid, char *cmdline); pid_t find_pid_from_cmdline(char *cmdline); /** + * @desc find pid from /proc + */ +void proc_foreach_pid(proc_pid_cb cb, void *user_data); + +/** * @desc get smack subject label from /proc/{pid}/attr/current * this label can indicate package name about child processes * @return negative value if error or pid doesn't exist diff --git a/src/stc-manager-plugin-procfs.c b/src/stc-manager-plugin-procfs.c old mode 100644 new mode 100755 index b83a7e8..1067f5e --- a/src/stc-manager-plugin-procfs.c +++ b/src/stc-manager-plugin-procfs.c @@ -67,6 +67,17 @@ int stc_plugin_procfs_deinit(void) return STC_ERROR_NONE; } +stc_error_e stc_plugin_procfs_load_pid(void) +{ + if (!stc_plugin_enabled) + return STC_ERROR_UNINITIALIZED; + + if (!stc_plugin) + return STC_ERROR_UNINITIALIZED; + + return stc_plugin->procfs_load(); +} + stc_error_e stc_plugin_procfs_app_status_changed(stc_cmd_type_e cmd, pid_t pid, const gchar *app_id, const gchar *pkg_id, stc_app_type_e app_type) { diff --git a/src/stc-manager.c b/src/stc-manager.c old mode 100644 new mode 100755 index 799839e..00854ea --- a/src/stc-manager.c +++ b/src/stc-manager.c @@ -110,6 +110,7 @@ static stc_s *__stc_manager_init(void) if (err != STC_ERROR_NONE) goto handle_error; + stc_plugin_procfs_load_pid(); stc_manager_gdbus_init((gpointer)stc); STC_LOGI("stc manager initialized");