#include <glib.h>
#include "stc-plugin-procfs.h"
-#include "stc-monitor.h"
#include "helper-net-cls.h"
#include "helper-procfs.h"
+#include "stc-manager-plugin-monitor.h"
+#include "stc-manager-plugin-exception.h"
//LCOV_EXCL_START
typedef struct {
static guint nl_connector_gsource_id = 0;
static GTree *proc_tree;
-
static gboolean __process_nl_connector_message(GIOChannel *source,
GIOCondition condition,
gpointer user_data);
parent = lookup;
} while (lookup);
- if (STC_DEBUG_LOG) {
+ if (STC_STAT_LOG) {
if (parent != NULL)
STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] "
"pid[%s] ppid[%s] cmdline[\033[0;34m%s\033[0;m] name[%s]",
}
if (key == NULL || value == NULL) {
- if (STC_DEBUG_LOG)
+ if (STC_STAT_LOG)
STC_LOGE("invalid parameters");
return;
}
if (cmdline[0] == '(')
return TRUE;
- ret = stc_monitor_check_excn_by_cmdline(cmdline);
+ ret = stc_plugin_check_exception_by_cmdline(cmdline);
if (ret == STC_ERROR_UNINITIALIZED ||
ret == STC_ERROR_NO_DATA)
return FALSE;
if (STC_ERROR_NONE == proc_get_cmdline(pid, cmdline) &&
STC_ERROR_NONE == proc_get_status(pid, status)) {
- if (__check_excn(cmdline)) {
- if (STC_DEBUG_LOG)
- STC_LOGD("[%s] monitoring is excepted", cmdline);
+ if (__check_excn(cmdline))
return;
- }
unsigned int i;
proc_key_s key;
g_strlcpy(value.status[i], status[i], sizeof(value.status[i]));
g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
- if (STC_DEBUG_LOG)
+ if (STC_STAT_LOG)
STC_LOGD("\033[1;32mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] "
"ppid=[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]",
tgid, status[PROC_STATUS_PPID], cmdline, pid);
if (STC_ERROR_NONE == proc_get_cmdline(pid, cmdline) &&
STC_ERROR_NONE == proc_get_status(pid, status)) {
- if (__check_excn(cmdline)) {
- if (STC_DEBUG_LOG)
- STC_LOGD("[%s] monitoring is excepted", cmdline);
+ if (__check_excn(cmdline))
return;
- }
unsigned int i;
proc_key_s key;
sizeof(value.status[i]));
g_strlcpy(value.cmdline, cmdline, sizeof(value.cmdline));
- if (STC_DEBUG_LOG)
+ if (STC_STAT_LOG)
STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] "
"ppid[%s] cmdline[\033[0;34m%s\033[0;m] pid[%d]",
tgid, status[PROC_STATUS_PPID], cmdline, pid);
if (lookup == NULL) /* unmonitored process */
return;
- if (STC_DEBUG_LOG)
+ if (STC_STAT_LOG)
STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] "
"cmdline[\033[0;34m%s\033[0;m] pid[%d] exitcode[%d]",
tgid, lookup->cmdline, pid, exit_code);
if (sock == -1) {
__STC_LOG_FUNC_EXIT__;
- return -1;
+ return STC_ERROR_INVALID_PARAMETER;
}
memset(&msg, 0, sizeof(nl_connector_msg_s));
if (ret == -1) {
STC_LOGE("Error sending netlink connector message");
__STC_LOG_FUNC_EXIT__;
- return -1;
+ return STC_ERROR_FAIL;
}
__STC_LOG_FUNC_EXIT__;
- return 0;
+ return STC_ERROR_NONE;
}
static int __unsubscribe_proc_events(void)
if (sock == -1) {
__STC_LOG_FUNC_EXIT__;
- return -1;
+ return STC_ERROR_INVALID_PARAMETER;
}
memset(&msg, 0, sizeof(nl_connector_msg_s));
if (ret == -1) {
STC_LOGE("Error sending netlink connector message");
__STC_LOG_FUNC_EXIT__;
- return -1;
+ return STC_ERROR_FAIL;
}
__STC_LOG_FUNC_EXIT__;
- return 0;
+ return STC_ERROR_NONE;
}
static bool __process_pid_cb(pid_t pid, void *user_data)
int stc_plugin_procfs_initialize(void)
{
__STC_LOG_FUNC_ENTER__;
+ int ret = STC_ERROR_NONE;
proc_tree = g_tree_new_full(__proc_tree_key_compare, NULL,
__proc_tree_key_free,
/* TODO: Fill proc tree with current procfs state */
__open_nl_connector_sock();
- __subscribe_proc_events();
+ ret = __subscribe_proc_events();
+
__STC_LOG_FUNC_EXIT__;
- return STC_ERROR_NONE;
+ return ret;
}
int stc_plugin_procfs_deinitialize(void)
{
__STC_LOG_FUNC_ENTER__;
+ int ret = STC_ERROR_NONE;
if (nl_connector_sock == -1) {
STC_LOGD("socket already closed");
return STC_ERROR_NONE;
}
- __unsubscribe_proc_events();
+ ret = __unsubscribe_proc_events();
__close_nl_connector_sock();
g_tree_destroy(proc_tree);
proc_tree = NULL;
__STC_LOG_FUNC_EXIT__;
- return STC_ERROR_NONE;
+ return ret;
}
stc_error_e stc_plugin_procfs_load(void)
{
stc_error_e ret = STC_ERROR_NONE;
- if ((pkg_id && app_id) && STC_DEBUG_LOG)
+ if ((pkg_id && app_id) && STC_STAT_LOG)
STC_LOGD("cmd[%d] pkgid[%s] appid[%s] pid[%d] type[%d]",
cmd, pkg_id, app_id, pid, app_type);
switch (cmd) {
case STC_CMD_SET_FOREGRD:
{
- uint32_t classid;
+ uint32_t fg_classid;
+ uint32_t bg_classid;
char *bg_app_id;
stc_app_value_s app_value;
stc_proc_value_s proc_value;
bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
app_value.type = app_type;
+ app_value.state = STC_APP_STATE_FOREGROUND;
app_value.processes = NULL;
proc_value.pid = pid;
proc_value.ground = STC_APP_STATE_FOREGROUND;
- classid = get_classid_by_app_id(bg_app_id, FALSE);
- stc_monitor_proc_remove(classid, pid);
+ bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
+ fg_classid = get_classid_by_app_id(app_id, TRUE);
- classid = get_classid_by_app_id(app_id, TRUE);
+ stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
- stc_monitor_app_add(classid, app_id, pkg_id, app_value);
- stc_monitor_proc_add(classid, app_id, proc_value);
- stc_monitor_proc_update_ground(classid, app_id, proc_value);
+ stc_plugin_monitor_move_proc(bg_classid, fg_classid);
+
+ stc_plugin_monitor_add_proc(fg_classid, app_id, proc_value);
+ stc_plugin_monitor_update_proc_ground(fg_classid, app_id, proc_value);
FREE(bg_app_id);
break;
}
case STC_CMD_SET_BACKGRD:
{
- uint32_t classid;
+ uint32_t bg_classid;
+ uint32_t fg_classid;
char *bg_app_id;
stc_app_value_s app_value;
stc_proc_value_s proc_value;
bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
app_value.type = app_type;
+ app_value.state = STC_APP_STATE_BACKGROUND;
app_value.processes = NULL;
proc_value.pid = pid;
proc_value.ground = STC_APP_STATE_BACKGROUND;
- classid = get_classid_by_app_id(app_id, FALSE);
- stc_monitor_proc_remove(classid, pid);
+ fg_classid = get_classid_by_app_id(app_id, FALSE);
+ bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
+
+ stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
- classid = get_classid_by_app_id(bg_app_id, TRUE);
+ stc_plugin_monitor_move_proc(fg_classid, bg_classid);
- stc_monitor_app_add(classid, bg_app_id, pkg_id, app_value);
- stc_monitor_proc_add(classid, bg_app_id, proc_value);
- stc_monitor_proc_update_ground(classid, bg_app_id, proc_value);
+ stc_plugin_monitor_add_proc(bg_classid, bg_app_id, proc_value);
+ stc_plugin_monitor_update_proc_ground(bg_classid, bg_app_id, proc_value);
FREE(bg_app_id);
break;
char *bg_app_id;
stc_app_value_s app_value;
stc_proc_value_s proc_value;
+ gboolean is_exist;
memset(&app_value, 0, sizeof(stc_app_value_s));
memset(&proc_value, 0, sizeof(stc_proc_value_s));
- bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+ classid = get_classid_by_app_id(app_id, FALSE);
+ is_exist = stc_plugin_monitor_lookup_app(classid);
+ if (is_exist) {
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_FOREGROUND;
+ app_value.processes = NULL;
- app_value.type = app_type;
- app_value.processes = NULL;
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_FOREGROUND;
- proc_value.pid = pid;
- proc_value.ground = STC_APP_STATE_BACKGROUND;
+ stc_plugin_monitor_add_app(classid, app_id, pkg_id, app_value);
+ stc_plugin_monitor_add_proc(classid, app_id, proc_value);
+ } else {
+ bg_app_id = g_strconcat(app_id, STC_BACKGROUND_APP_SUFFIX, NULL);
+ classid = get_classid_by_app_id(bg_app_id, TRUE);
- classid = get_classid_by_app_id(bg_app_id, TRUE);
+ app_value.type = app_type;
+ app_value.state = STC_APP_STATE_BACKGROUND;
+ app_value.processes = NULL;
- stc_monitor_app_add(classid, bg_app_id, pkg_id, app_value);
- stc_monitor_proc_add(classid, bg_app_id, proc_value);
+ proc_value.pid = pid;
+ proc_value.ground = STC_APP_STATE_BACKGROUND;
- FREE(bg_app_id);
+ stc_plugin_monitor_add_app(classid, bg_app_id, pkg_id, app_value);
+ stc_plugin_monitor_add_proc(classid, bg_app_id, proc_value);
+
+ FREE(bg_app_id);
+ }
break;
}
case STC_CMD_SET_TERMINATED:
if (classid == STC_UNKNOWN_CLASSID)
classid = get_classid_by_app_id(app_id, FALSE);
- stc_monitor_proc_remove(classid, pid);
+ stc_plugin_monitor_remove_proc(classid, pid);
FREE(bg_app_id);
break;