Fix a svace issue for negative code error
[platform/core/connectivity/stc-manager.git] / plugin / procfs / stc-plugin-procfs.c
index 4aa36c6..9538a61 100755 (executable)
 #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 {
@@ -135,7 +136,7 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
                        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]",
@@ -158,7 +159,7 @@ static void __proc_tree_add(proc_key_s *key, proc_value_s *value)
        }
 
        if (key == NULL || value == NULL) {
-               if (STC_DEBUG_LOG)
+               if (STC_STAT_LOG)
                        STC_LOGE("invalid parameters");
                return;
        }
@@ -223,7 +224,7 @@ static gboolean __check_excn(char *cmdline)
        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;
@@ -318,7 +319,7 @@ static void __process_event_fork(int tgid, int pid)
                        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);
@@ -357,7 +358,7 @@ static void __process_event_exec(int tgid, int pid)
                                  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);
@@ -379,7 +380,7 @@ static void __process_event_exit(int tgid, int pid, int exit_code)
        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);
@@ -446,7 +447,7 @@ static int __subscribe_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));
@@ -465,11 +466,11 @@ static int __subscribe_proc_events(void)
        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)
@@ -481,7 +482,7 @@ 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));
@@ -500,11 +501,11 @@ static int __unsubscribe_proc_events(void)
        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)
@@ -541,6 +542,7 @@ 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,
@@ -549,28 +551,30 @@ int stc_plugin_procfs_initialize(void)
        /* 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)
@@ -591,7 +595,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
 {
        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);
 
@@ -619,12 +623,12 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                bg_classid = get_classid_by_app_id(bg_app_id, FALSE);
                fg_classid = get_classid_by_app_id(app_id, TRUE);
 
-               stc_monitor_app_add(fg_classid, app_id, pkg_id, app_value);
+               stc_plugin_monitor_add_app(fg_classid, app_id, pkg_id, app_value);
 
-               stc_monitor_proc_move(bg_classid, fg_classid);
+               stc_plugin_monitor_move_proc(bg_classid, fg_classid);
 
-               stc_monitor_proc_add(fg_classid, app_id, proc_value);
-               stc_monitor_proc_update_ground(fg_classid, app_id, proc_value);
+               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;
@@ -652,12 +656,12 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                fg_classid = get_classid_by_app_id(app_id, FALSE);
                bg_classid = get_classid_by_app_id(bg_app_id, TRUE);
 
-               stc_monitor_app_add(bg_classid, bg_app_id, pkg_id, app_value);
+               stc_plugin_monitor_add_app(bg_classid, bg_app_id, pkg_id, app_value);
 
-               stc_monitor_proc_move(fg_classid, bg_classid);
+               stc_plugin_monitor_move_proc(fg_classid, bg_classid);
 
-               stc_monitor_proc_add(bg_classid, bg_app_id, proc_value);
-               stc_monitor_proc_update_ground(bg_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;
@@ -674,7 +678,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                memset(&proc_value, 0, sizeof(stc_proc_value_s));
 
                classid = get_classid_by_app_id(app_id, FALSE);
-               is_exist = stc_monitor_app_lookup(classid);
+               is_exist = stc_plugin_monitor_lookup_app(classid);
                if (is_exist) {
                        app_value.type = app_type;
                        app_value.state = STC_APP_STATE_FOREGROUND;
@@ -683,8 +687,8 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                        proc_value.pid = pid;
                        proc_value.ground = STC_APP_STATE_FOREGROUND;
 
-                       stc_monitor_app_add(classid, app_id, pkg_id, app_value);
-                       stc_monitor_proc_add(classid, app_id, proc_value);
+                       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);
@@ -696,8 +700,8 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                        proc_value.pid = pid;
                        proc_value.ground = STC_APP_STATE_BACKGROUND;
 
-                       stc_monitor_app_add(classid, bg_app_id, pkg_id, app_value);
-                       stc_monitor_proc_add(classid, bg_app_id, proc_value);
+                       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);
                }
@@ -714,7 +718,7 @@ stc_error_e stc_plugin_procfs_status_changed(stc_cmd_type_e cmd,
                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;