Fix dbus connection free 94/117994/1
authorWonnam Jang <wn.jang@samsung.com>
Mon, 6 Mar 2017 06:31:08 +0000 (15:31 +0900)
committerSuyeon Hwang <stom.hwang@samsung.com>
Wed, 8 Mar 2017 08:20:09 +0000 (00:20 -0800)
Change-Id: I6919a56db1e341be51373c9aa0b66e4cd55bac42
Signed-off-by: Wonnam Jang <wn.jang@samsung.com>
(cherry picked from commit 18bc92d77bec4a6784e8ea782383140fe9d501c5)

client/vc_dbus.c
client/vc_mgr_dbus.c
client/vc_widget_dbus.c

index 27f4d5478a98de93171d75f6f56a350ec44328d6..183639695e1a4c153d8485eebf62acb0a96581e1 100644 (file)
@@ -192,6 +192,20 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
        return ECORE_CALLBACK_PASS_ON;
 }
 
+static void __vc_dbus_connection_free()
+{
+       if (NULL != g_conn_listener) {
+               dbus_connection_close(g_conn_listener);
+               dbus_connection_unref(g_conn_listener);
+               g_conn_listener = NULL;
+       }
+       if (NULL != g_conn_sender) {
+               dbus_connection_close(g_conn_sender);
+               dbus_connection_unref(g_conn_sender);
+               g_conn_sender = NULL;
+       }
+}
+
 int vc_dbus_open_connection()
 {
        if (NULL != g_conn_sender && NULL != g_conn_listener) {
@@ -227,6 +241,7 @@ int vc_dbus_open_connection()
 
        if (NULL == g_conn_listener) {
                SLOG(LOG_ERROR, TAG_VCC, "Fail to get dbus connection ");
+               __vc_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -248,11 +263,13 @@ int vc_dbus_open_connection()
 
        if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
                SLOG(LOG_ERROR, TAG_VCC, "fail dbus_bus_request_name()");
+               __vc_dbus_connection_free();
                return -2;
        }
 
        if (NULL != g_fd_handler) {
                SLOG(LOG_WARN, TAG_VCC, "The handler already exists.");
+               __vc_dbus_connection_free();
                return 0;
        }
 
@@ -266,12 +283,14 @@ int vc_dbus_open_connection()
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_VCC, "Match Error (%s)", err.message);
                dbus_error_free(&err);
+               __vc_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
        int fd = 0;
        if (1 != dbus_connection_get_unix_fd(g_conn_listener, &fd)) {
                SLOG(LOG_ERROR, TAG_VCC, "fail to get fd from dbus ");
+               __vc_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCC, "Get fd from dbus : %d", fd);
@@ -280,6 +299,7 @@ int vc_dbus_open_connection()
        g_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, (Ecore_Fd_Cb)listener_event_callback, g_conn_listener, NULL, NULL);
        if (NULL == g_fd_handler) {
                SLOG(LOG_ERROR, TAG_VCC, "fail to get fd handler from ecore ");
+               __vc_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -309,20 +329,25 @@ int vc_dbus_close_connection()
                dbus_error_free(&err);
        }
 
-       dbus_connection_close(g_conn_sender);
-       dbus_connection_close(g_conn_listener);
-
-       dbus_connection_unref(g_conn_sender);
-       dbus_connection_unref(g_conn_listener);
-
-       g_conn_sender = NULL;
-       g_conn_listener = NULL;
+       __vc_dbus_connection_free();
 
        return 0;
 }
 
 int vc_dbus_reconnect()
 {
+       if (!g_conn_sender || !g_conn_listener) {
+               vc_dbus_close_connection();
+
+               if (0 != vc_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to reconnect");
+                       return -1;
+               }
+
+               SLOG(LOG_DEBUG, TAG_VCC, "[DBUS] Reconnect");
+               return 0;
+       }
+
        bool sender_connected = dbus_connection_get_is_connected(g_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_conn_listener);
        SLOG(LOG_WARN, TAG_VCC, "[DBUS] Sender(%s) Listener(%s)",
index 7133c92682776ca0ef1158a9d1c22b7123ee3f38..fe4ad319c107ca2bf79000404887f171b983969e 100644 (file)
@@ -496,6 +496,20 @@ static Eina_Bool vc_mgr_listener_event_callback(void* data, Ecore_Fd_Handler *fd
        return ECORE_CALLBACK_PASS_ON;
 }
 
+static void __vc_mgr_dbus_connection_free()
+{
+       if (NULL != g_m_conn_listener) {
+               dbus_connection_close(g_m_conn_listener);
+               dbus_connection_unref(g_m_conn_listener);
+               g_m_conn_listener = NULL;
+       }
+       if (NULL != g_m_conn_sender) {
+               dbus_connection_close(g_m_conn_sender);
+               dbus_connection_unref(g_m_conn_sender);
+               g_m_conn_sender = NULL;
+       }
+}
+
 int vc_mgr_dbus_open_connection()
 {
        if (NULL != g_m_conn_sender && NULL != g_m_conn_listener) {
@@ -532,6 +546,7 @@ int vc_mgr_dbus_open_connection()
 
        if (NULL == g_m_conn_listener) {
                SLOG(LOG_ERROR, TAG_VCM, "Fail to get dbus connection ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -547,11 +562,13 @@ int vc_mgr_dbus_open_connection()
 
        if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
                SLOG(LOG_ERROR, TAG_VCM, "fail dbus_bus_request_name()");
+               __vc_mgr_dbus_connection_free();
                return -2;
        }
 
        if (NULL != g_m_fd_handler) {
                SLOG(LOG_WARN, TAG_VCM, "The handler already exists.");
+               __vc_mgr_dbus_connection_free();
                return 0;
        }
 
@@ -565,12 +582,14 @@ int vc_mgr_dbus_open_connection()
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_VCM, "Match Error (%s)", err.message);
                dbus_error_free(&err);
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
        int fd = 0;
        if (1 != dbus_connection_get_unix_fd(g_m_conn_listener, &fd)) {
                SLOG(LOG_ERROR, TAG_VCM, "fail to get fd from dbus ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCM, "Get fd from dbus : %d", fd);
@@ -580,6 +599,7 @@ int vc_mgr_dbus_open_connection()
 
        if (NULL == g_m_fd_handler) {
                SLOG(LOG_ERROR, TAG_VCM, "fail to get fd handler from ecore ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -609,20 +629,25 @@ int vc_mgr_dbus_close_connection()
                dbus_error_free(&err);
        }
 
-       dbus_connection_close(g_m_conn_sender);
-       dbus_connection_close(g_m_conn_listener);
-
-       dbus_connection_unref(g_m_conn_sender);
-       dbus_connection_unref(g_m_conn_listener);
-
-       g_m_conn_sender = NULL;
-       g_m_conn_listener = NULL;
+       __vc_mgr_dbus_connection_free();
 
        return 0;
 }
 
 int vc_mgr_dbus_reconnect()
 {
+       if (!g_m_conn_sender || !g_m_conn_listener) {
+               vc_mgr_dbus_close_connection();
+
+               if (0 != vc_mgr_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Fail to reconnect");
+                       return -1;
+               }
+
+               SLOG(LOG_DEBUG, TAG_VCM, "[DBUS] Reconnect");
+               return 0;
+       }
+
        bool sender_connected = dbus_connection_get_is_connected(g_m_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_m_conn_listener);
 
index 56937b4768ba89c36226b18925fb47ff912ad593..18dbe2c63901bd8739a172e7229d677e5030eeff 100644 (file)
@@ -268,6 +268,20 @@ static Eina_Bool widget_listener_event_callback(void* data, Ecore_Fd_Handler *fd
        return ECORE_CALLBACK_PASS_ON;
 }
 
+static void __vc_mgr_dbus_connection_free()
+{
+       if (NULL != g_w_conn_listener) {
+               dbus_connection_close(g_w_conn_listener);
+               dbus_connection_unref(g_w_conn_listener);
+               g_w_conn_listener = NULL;
+       }
+       if (NULL != g_w_conn_sender) {
+               dbus_connection_close(g_w_conn_sender);
+               dbus_connection_unref(g_w_conn_sender);
+               g_w_conn_sender = NULL;
+       }
+}
+
 int vc_widget_dbus_open_connection()
 {
        if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) {
@@ -303,6 +317,7 @@ int vc_widget_dbus_open_connection()
 
        if (NULL == g_w_conn_listener) {
                SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -324,11 +339,13 @@ int vc_widget_dbus_open_connection()
 
        if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
                SLOG(LOG_ERROR, TAG_VCW, "fail dbus_bus_request_name()");
+               __vc_mgr_dbus_connection_free();
                return -2;
        }
 
        if (NULL != g_w_fd_handler) {
                SLOG(LOG_WARN, TAG_VCW, "The handler already exists.");
+               __vc_mgr_dbus_connection_free();
                return 0;
        }
 
@@ -342,12 +359,14 @@ int vc_widget_dbus_open_connection()
        if (dbus_error_is_set(&err)) {
                SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
                dbus_error_free(&err);
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
        int fd = 0;
        if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) {
                SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd);
@@ -357,6 +376,7 @@ int vc_widget_dbus_open_connection()
 
        if (NULL == g_w_fd_handler) {
                SLOG(LOG_ERROR, TAG_VCW, "fail to get fd handler from ecore ");
+               __vc_mgr_dbus_connection_free();
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -386,20 +406,25 @@ int vc_widget_dbus_close_connection()
                dbus_error_free(&err);
        }
 
-       dbus_connection_close(g_w_conn_sender);
-       dbus_connection_close(g_w_conn_listener);
-
-       dbus_connection_unref(g_w_conn_sender);
-       dbus_connection_unref(g_w_conn_listener);
-
-       g_w_conn_sender = NULL;
-       g_w_conn_listener = NULL;
+       __vc_mgr_dbus_connection_free();
 
        return 0;
 }
 
 int vc_widget_dbus_reconnect()
 {
+       if (!g_w_conn_sender || !g_w_conn_listener) {
+               vc_widget_dbus_close_connection();
+
+               if (0 != vc_widget_dbus_open_connection()) {
+                       SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to reconnect");
+                       return -1;
+               }
+
+               SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Reconnect");
+               return 0;
+       }
+
        bool sender_connected = dbus_connection_get_is_connected(g_w_conn_sender);
        bool listener_connected = dbus_connection_get_is_connected(g_w_conn_listener);
        SLOG(LOG_DEBUG, TAG_VCW, "[DBUS] Sender(%s) Listener(%s)",