Reopening socket if G_IO error is received and updated debug logs. 96/136196/3 accepted/tizen/unified/20170703.064211 submit/tizen/20170630.014944
authorNishant Chaprana <n.chaprana@samsung.com>
Wed, 28 Jun 2017 11:15:39 +0000 (16:45 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Wed, 28 Jun 2017 11:28:04 +0000 (16:58 +0530)
Change-Id: I58ee40fe4b3349dd26117907347893d892fd0a63
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
packaging/stc-manager.spec
src/database/tables/table-statistics.c
src/helper/helper-net-cls.c
src/helper/helper-nfacct-rule.c
src/monitor/stc-default-connection.c
src/monitor/stc-monitor.c
src/stc-manager.c

index d9ab976675422e7fca83821a6df242b70868f55d..cfd59dd7501dbd0ea5d8a1cb72a35a05440b3c04 100644 (file)
@@ -1,6 +1,6 @@
 Name:       stc-manager
 Summary:    STC(Smart Traffic Control) manager
-Version:    0.0.18
+Version:    0.0.19
 Release:    0
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
index e16059a354b5e3c9be51207b8ec6abd5bb343425..73c298d670ab02f0e741964e2e9210acb4a6cfe2 100755 (executable)
@@ -619,7 +619,7 @@ stc_error_e table_statistics_insert(stc_db_classid_iftype_key *stat_key,
                goto handle_error;
        }
 
-       STC_LOGE("App stat recorded [%s]", stat->app_id);
+       STC_LOGD("App stat recorded [%s]", stat->app_id);
 
 handle_error:
        sqlite3_reset(stmt);
index 8f3f5d046825615747fa2a61a4e7a1d024b12727..826ff7d742a1b71cf9ee59a184e8cd937112eb39 100755 (executable)
@@ -37,7 +37,7 @@ static uint32_t __produce_classid(check_classid_used_cb check_classid_cb)
        int classid_test_count = 0;
        int ret = fread_uint(CUR_CLASSID_PATH, &classid);
        if (ret < 0)
-               STC_LOGE("Can not read current classid");
+               STC_LOGI("Can not read current classid");
        classid += 1;
        if (check_classid_cb)
                for (classid_test_count = 0; classid_test_count < INT32_MAX;
index 1eb140bce319841dcdaa8e6ba9f8fb31c9242b1a..315a465812ab80c188ff0710d686625fa39aac21 100755 (executable)
@@ -126,7 +126,7 @@ static stc_error_e send_nfacct_request(int sock, struct genl *req)
        int ret = sendto(sock, (char *)(&req->n), req->n.nlmsg_len, 0,
                         (struct sockaddr *)&nladdr, sizeof(nladdr));
        ret_value_msg_if(ret < 0, STC_ERROR_FAIL,
-                        "Failed to send command to get outgoing traffic");
+                        "Failed to send nfacct request, error [%d]", ret);
 
        return STC_ERROR_NONE;
 }
index 9aad6fb5a70308d32505a22df1b76739d203b312..ad9b74fb5afef21e3ca70457e6ae3ee3734d5a68 100755 (executable)
@@ -140,7 +140,7 @@ static void __get_default_connection_info(GDBusConnection *connection,
        gchar *key = NULL;
 
        if (object_path == NULL) {
-               STC_LOGE("Object path is NULL");
+               STC_LOGI("Object path is NULL, so information not available.");
                return;
        }
 
index 835e29f3e13b77c9cd92999d36b96e85fa447ffc..31dadf6923c9765267176a9d3f16339929acdcf3 100755 (executable)
@@ -540,19 +540,57 @@ static stc_error_e __close_contr_sock(stc_system_s *system)
        ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
 
        /* close netlink socket for updating kernel counters */
-       if (g_system->contr_sock != -1) {
-               close(g_system->contr_sock);
-               g_system->contr_sock = -1;
+       if (system->contr_sock != -1) {
+               close(system->contr_sock);
+               system->contr_sock = -1;
        }
 
-       if (g_system->contr_gsource_id != 0) {
-               g_source_remove(g_system->contr_gsource_id);
-               g_system->contr_gsource_id = 0;
+       if (system->contr_gsource_id != 0) {
+               g_source_remove(system->contr_gsource_id);
+               system->contr_gsource_id = 0;
        }
 
        return STC_ERROR_NONE;
 }
 
+static gboolean __process_contr_reply(GIOChannel *source,
+                                     GIOCondition condition,
+                                     gpointer user_data);
+
+static stc_error_e __close_and_reopen_contr_sock(stc_system_s *system)
+{
+       GIOChannel *gio = NULL;
+       ret_value_msg_if(system == NULL, STC_ERROR_INVALID_PARAMETER, "invalid parameter");
+
+       /* close netlink socket for updating kernel counters */
+       if (system->contr_sock != -1) {
+               close(system->contr_sock);
+               system->contr_sock = -1;
+       }
+
+       if (system->contr_gsource_id != 0) {
+               g_source_remove(system->contr_gsource_id);
+               system->contr_gsource_id = 0;
+       }
+
+       /* create netlink socket for updating kernel counters */
+       system->contr_sock = create_netlink(NETLINK_NETFILTER, 0);
+       if (!(system->contr_sock)) {
+               STC_LOGE("failed to open socket");
+               FREE(system);
+               return STC_ERROR_FAIL;
+       }
+
+       gio = g_io_channel_unix_new(system->contr_sock);
+       system->contr_gsource_id =
+               g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP,
+                              (GIOFunc) __process_contr_reply,
+                              NULL);
+       g_io_channel_unref(gio);
+
+       return STC_ERROR_NONE;
+}
+
 static gboolean __rstn_counter_update_foreach_classid(gpointer key,
                                                      gpointer value,
                                                      gpointer data)
@@ -884,7 +922,11 @@ static gboolean __process_contr_reply(GIOChannel *source,
            (condition & G_IO_NVAL)) {
                /* G_IO_ERR/G_IO_HUP/G_IO_NVAL received */
 
-               __close_contr_sock(g_system);
+               STC_LOGE("Counter socket received G_IO event, closing 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));
+               __close_and_reopen_contr_sock(g_system);
                return FALSE;
        }
 
index a732b72c67cc69d8ddb813ab3ae52533f6ad11bf..1f856ef95c7d330aca247a0decd9ce26ac6103a7 100755 (executable)
@@ -54,6 +54,7 @@ static stc_s *__stc_manager_init(void)
 {
        __STC_LOG_FUNC_ENTER__;
        stc_s *stc;
+       stc_error_e err = STC_ERROR_NONE;
 
        stc = MALLOC0(stc_s, 1);
        if (!stc) {
@@ -66,7 +67,10 @@ static stc_s *__stc_manager_init(void)
 
        EXEC(STC_ERROR_NONE, stc_db_initialize());
 
-       stc_monitor_init();
+       err = stc_monitor_init();
+       if (err != STC_ERROR_NONE)
+               goto handle_error;
+
        stc_manager_gdbus_init((gpointer)stc);
        stc_manager_plugin_init();