Add initial source codes for gtest
[platform/core/connectivity/stc-manager.git] / src / monitor / stc-app-lifecycle.c
index 1cd8e9d..d02667f 100755 (executable)
@@ -93,14 +93,15 @@ static proc_value_s * __proc_tree_lookup(const proc_key_s *key)
        proc_value_s *lookup;
 
        if (proc_tree == NULL) {
-               STC_LOGE("tree is null");
-               return NULL;
+               STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+               return NULL; //LCOV_EXCL_LINE
        }
 
        lookup = g_tree_lookup(proc_tree, key);
        return lookup;
 }
 
+//LCOV_EXCL_START
 static gboolean __proc_tree_foreach_print(gpointer key, gpointer value,
                                          gpointer data)
 {
@@ -113,10 +114,11 @@ static gboolean __proc_tree_foreach_print(gpointer key, gpointer value,
 
        return FALSE;
 }
+//LCOV_EXCL_STOP
 
 static void __proc_tree_printall(void)
 {
-       g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL);
+       g_tree_foreach(proc_tree, __proc_tree_foreach_print, NULL); //LCOV_EXCL_LINE
 }
 
 static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
@@ -133,8 +135,8 @@ static proc_value_s * __proc_tree_find_parent(proc_value_s *value)
        } while (lookup);
 
        if (STC_DEBUG_LOG) {
-               if (parent != NULL)
-                       STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] "
+               if (parent != NULL) //LCOV_EXCL_LINE
+                       STC_LOGD("\033[0;35mPARENT\033[0;m: tgid[\033[1;33m%s\033[0;m] pid[%s] " //LCOV_EXCL_LINE
                                "ppid[\033[1;35m%s\033[0;m] cmdline[\033[0;34m%s\033[0;m] name[%s]",
                                parent->status[PROC_STATUS_TGID], parent->status[PROC_STATUS_PID],
                                parent->status[PROC_STATUS_PPID], parent->cmdline,
@@ -151,14 +153,14 @@ static void __proc_tree_add(proc_key_s *key,
        proc_value_s *parent;
 
        if (proc_tree == NULL) {
-               STC_LOGE("tree is null");
-               return;
+               STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        lookup = g_tree_lookup(proc_tree, key);
        if (lookup) {
                if (STC_DEBUG_LOG)
-                       STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] "
+                       STC_LOGD("LOOKUP: tgid[\033[1;33m%s\033[0;m] pid[%s] ppid[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
                                "cmdline[\033[0;34m%s\033[0;m] name[%s]", lookup->status[PROC_STATUS_TGID],
                                lookup->status[PROC_STATUS_PID], lookup->status[PROC_STATUS_PPID],
                                lookup->cmdline, lookup->status[PROC_STATUS_NAME]);
@@ -185,8 +187,8 @@ static void __proc_tree_add(proc_key_s *key,
 static void __proc_tree_remove(const proc_key_s *key)
 {
        if (proc_tree == NULL) {
-               STC_LOGE("tree is null");
-               return;
+               STC_LOGE("tree is null"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        stc_manager_app_status_changed(STC_CMD_SET_TERMINATED, key->pid, NULL,
@@ -195,7 +197,7 @@ static void __proc_tree_remove(const proc_key_s *key)
        g_tree_remove(proc_tree, key);
 
        if (STC_DEBUG_LOG)
-               __proc_tree_printall();
+               __proc_tree_printall(); //LCOV_EXCL_LINE
 }
 
 static gboolean __check_excn(char *cmdline)
@@ -218,26 +220,26 @@ static void __open_nl_connector_sock(void)
        GIOChannel *gio = NULL;
 
        if (nl_connector_sock != -1 &&
-           nl_connector_gsource_id != 0) {
-               STC_LOGE("Socket is already open");
-               __STC_LOG_FUNC_EXIT__;
-               return;
+           nl_connector_gsource_id != 0) { //LCOV_EXCL_LINE
+               STC_LOGE("Socket is already open"); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        if (nl_connector_sock != -1) {
-               close(nl_connector_sock);
-               nl_connector_sock = -1;
+               close(nl_connector_sock); //LCOV_EXCL_LINE
+               nl_connector_sock = -1; //LCOV_EXCL_LINE
        }
 
        if (nl_connector_gsource_id != 0) {
-               g_source_remove(nl_connector_gsource_id);
-               nl_connector_gsource_id = 0;
+               g_source_remove(nl_connector_gsource_id); //LCOV_EXCL_LINE
+               nl_connector_gsource_id = 0; //LCOV_EXCL_LINE
        }
 
        nl_connector_sock = create_netlink(NETLINK_CONNECTOR, CN_IDX_PROC);
        if (nl_connector_sock == -1) {
-               __STC_LOG_FUNC_EXIT__;
-               return;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        gio = g_io_channel_unix_new(nl_connector_sock);
@@ -266,10 +268,11 @@ static void __close_nl_connector_sock(void)
 
 static void __reopen_nl_connector_sock(void)
 {
-       __close_nl_connector_sock();
-       __open_nl_connector_sock();
+       __close_nl_connector_sock(); //LCOV_EXCL_LINE
+       __open_nl_connector_sock(); //LCOV_EXCL_LINE
 }
 
+//LCOV_EXCL_START
 stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
                                           pid_t pid,
                                           const gchar *app_id,
@@ -389,6 +392,7 @@ stc_error_e stc_manager_app_status_changed(stc_cmd_type_e cmd,
 
        return ret;
 }
+//LCOV_EXCL_STOP
 
 static void __process_event_fork(int tgid, int pid)
 {
@@ -402,7 +406,7 @@ static void __process_event_fork(int tgid, int pid)
 
                if (__check_excn(cmdline)) {
                        if (STC_DEBUG_LOG)
-                               STC_LOGD("[%s] monitoring is excepted", cmdline);
+                               STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE
                        return;
                }
 
@@ -412,15 +416,15 @@ static void __process_event_fork(int tgid, int pid)
 
                key = MALLOC0(proc_key_s, 1);
                if (key == NULL) {
-                       STC_LOGE("memory allocation failed");
-                       return;
+                       STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+                       return; //LCOV_EXCL_LINE
                }
 
                value = MALLOC0(proc_value_s, 1);
                if (value == NULL) {
-                       STC_LOGE("memory allocation failed");
-                       FREE(key);
-                       return;
+                       STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+                       FREE(key); //LCOV_EXCL_LINE
+                       return; //LCOV_EXCL_LINE
                }
 
                key->pid = tgid;
@@ -429,9 +433,9 @@ static void __process_event_fork(int tgid, int pid)
                g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline));
 
                if (STC_DEBUG_LOG) {
-                       STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
+                       STC_LOGD("\033[1;34mFORK\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
                                "cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
-                       STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
+                       STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE
                                status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
                                status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
                }
@@ -452,7 +456,7 @@ static void __process_event_exec(int tgid, int pid)
 
                if (__check_excn(cmdline)) {
                        if (STC_DEBUG_LOG)
-                               STC_LOGD("[%s] monitoring is excepted", cmdline);
+                               STC_LOGD("[%s] monitoring is excepted", cmdline); //LCOV_EXCL_LINE
                        return;
                }
 
@@ -462,15 +466,15 @@ static void __process_event_exec(int tgid, int pid)
 
                key = MALLOC0(proc_key_s, 1);
                if (key == NULL) {
-                       STC_LOGE("memory allocation failed");
-                       return;
+                       STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+                       return; //LCOV_EXCL_LINE
                }
 
                value = MALLOC0(proc_value_s, 1);
                if (value == NULL) {
-                       STC_LOGE("memory allocation failed");
-                       FREE(key);
-                       return;
+                       STC_LOGE("memory allocation failed"); //LCOV_EXCL_LINE
+                       FREE(key); //LCOV_EXCL_LINE
+                       return; //LCOV_EXCL_LINE
                }
 
                key->pid = tgid;
@@ -479,9 +483,9 @@ static void __process_event_exec(int tgid, int pid)
                g_strlcpy(value->cmdline, cmdline, sizeof(value->cmdline));
 
                if (STC_DEBUG_LOG) {
-                       STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] "
+                       STC_LOGD("\033[1;32mEXEC\033[0;m: tgid[\033[1;33m%d\033[0;m] ppid=[\033[1;35m%s\033[0;m] " //LCOV_EXCL_LINE
                                "cmdline[\033[0;34m%s\033[0;m] pid[%d]", tgid, status[PROC_STATUS_PPID], cmdline, pid);
-                       STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]",
+                       STC_LOGD("STATUS: tgid[%s] pid[%s] ppid[%s] name[%s] state[%s] tracerpid[%s]", //LCOV_EXCL_LINE
                                status[PROC_STATUS_TGID], status[PROC_STATUS_PID], status[PROC_STATUS_PPID],
                                status[PROC_STATUS_NAME], status[PROC_STATUS_STATE], status[PROC_STATUS_TRACERPID]);
                }
@@ -504,7 +508,7 @@ static void __process_event_exit(int tgid, int pid, int exit_code)
                return;
 
        if (STC_DEBUG_LOG)
-               STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] "
+               STC_LOGD("\033[1;31mEXIT\033[0;m: tgid[\033[1;33m%d\033[0;m] " //LCOV_EXCL_LINE
                        "pid[%d] exitcode[\033[0;31m%d\033[0;m]", tgid, pid, exit_code);
 
        __proc_tree_remove(&key);
@@ -522,21 +526,21 @@ static gboolean __process_nl_connector_message(GIOChannel *source,
            (condition & G_IO_NVAL)) {
                /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
 
-               STC_LOGE("Netlink Connector socket received G_IO event, closing"
+               STC_LOGE("Netlink Connector socket received G_IO event, closing" //LCOV_EXCL_LINE
                         " socket. G_IO_ERR [%d], G_IO_HUP [%d], G_IO_NVAL [%s]",
                         (condition & G_IO_ERR), (condition & G_IO_HUP),
                         (condition & G_IO_NVAL));
-               __reopen_nl_connector_sock();
-               __STC_LOG_FUNC_EXIT__;
-               return FALSE;
+               __reopen_nl_connector_sock(); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return FALSE; //LCOV_EXCL_LINE
        }
 
        memset(&msg, 0, sizeof(nl_connector_proc_event_s));
 
        ret = read(sock, &msg, sizeof(nl_connector_proc_event_s));
        if (ret == 0) {
-               __STC_LOG_FUNC_EXIT__;
-               return TRUE;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return TRUE; //LCOV_EXCL_LINE
        }
 
        switch (msg.proc_ev.what) {
@@ -568,8 +572,8 @@ static int __subscribe_proc_events(void)
        int sock = nl_connector_sock;
 
        if (sock == -1) {
-               __STC_LOG_FUNC_EXIT__;
-               return -1;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
        }
 
        memset(&msg, 0, sizeof(nl_connector_msg_s));
@@ -586,9 +590,9 @@ static int __subscribe_proc_events(void)
 
        ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0);
        if (ret == -1) {
-               STC_LOGE("Error sending netlink connector message");
-               __STC_LOG_FUNC_EXIT__;
-               return -1;
+               STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
        }
 
        __STC_LOG_FUNC_EXIT__;
@@ -603,8 +607,8 @@ static int __unsubscribe_proc_events(void)
        int sock = nl_connector_sock;
 
        if (sock == -1) {
-               __STC_LOG_FUNC_EXIT__;
-               return -1;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
        }
 
        memset(&msg, 0, sizeof(nl_connector_msg_s));
@@ -621,9 +625,9 @@ static int __unsubscribe_proc_events(void)
 
        ret = send(sock, &msg, sizeof(nl_connector_msg_s), 0);
        if (ret == -1) {
-               STC_LOGE("Error sending netlink connector message");
-               __STC_LOG_FUNC_EXIT__;
-               return -1;
+               STC_LOGE("Error sending netlink connector message"); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return -1; //LCOV_EXCL_LINE
        }
 
        __STC_LOG_FUNC_EXIT__;
@@ -650,8 +654,8 @@ void stc_app_lifecycle_monitor_deinit(void)
        __STC_LOG_FUNC_ENTER__;
 
        if (nl_connector_sock == -1) {
-               STC_LOGE("socket already closed");
-               return;
+               STC_LOGE("socket already closed"); //LCOV_EXCL_LINE
+               return; //LCOV_EXCL_LINE
        }
 
        __unsubscribe_proc_events();