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)
(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;
}