Load procfs on booting time 08/180508/1
authorhyunuktak <hyunuk.tak@samsung.com>
Wed, 30 May 2018 07:24:44 +0000 (16:24 +0900)
committerhyunuktak <hyunuk.tak@samsung.com>
Wed, 30 May 2018 07:24:47 +0000 (16:24 +0900)
Change-Id: If68c6428cfb364aff9fbfd2a904ff6fee82a6a4d
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
include/stc-manager-plugin-procfs.h [changed mode: 0644->0755]
packaging/stc-manager.spec
plugin/procfs/include/stc-plugin-procfs.h [changed mode: 0644->0755]
plugin/procfs/stc-plugin-procfs.c [changed mode: 0644->0755]
src/helper/helper-procfs.c [changed mode: 0644->0755]
src/helper/helper-procfs.h [changed mode: 0644->0755]
src/stc-manager-plugin-procfs.c [changed mode: 0644->0755]
src/stc-manager.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 83e7332..9e7b565
@@ -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);
 
index 7d6decf..52b858d 100644 (file)
@@ -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
old mode 100644 (file)
new mode 100755 (executable)
index 3a02bfe..7375041
@@ -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);
 
old mode 100644 (file)
new mode 100755 (executable)
index 36b8f78..80cf9b1
@@ -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
 };
old mode 100644 (file)
new mode 100755 (executable)
index 020987d..8cd0461
@@ -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];
old mode 100644 (file)
new mode 100755 (executable)
index 55c6a03..26839c6
@@ -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
old mode 100644 (file)
new mode 100755 (executable)
index b83a7e8..1067f5e
@@ -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)
 {
old mode 100644 (file)
new mode 100755 (executable)
index 799839e..00854ea
@@ -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");