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);
Name: stc-manager
Summary: STC(Smart Traffic Control) manager
-Version: 0.0.49
+Version: 0.0.50
Release: 0
Group: Network & Connectivity/Other
License: Apache-2.0
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;
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);
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__;
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, stc_app_type_e app_type)
{
stc_plugin_procfs_initialize,
.deinitialize_plugin =
stc_plugin_procfs_deinitialize,
+ .procfs_load =
+ stc_plugin_procfs_load,
.procfs_status_changed =
stc_plugin_procfs_status_changed
};
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];
#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
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
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)
{
if (err != STC_ERROR_NONE)
goto handle_error;
+ stc_plugin_procfs_load_pid();
stc_manager_gdbus_init((gpointer)stc);
STC_LOGI("stc manager initialized");