Fix dbus crash issue in vc widget 41/191041/1 accepted/tizen/unified/20181011.095005 submit/tizen/20181011.062222
authorsooyeon.kim <sooyeon.kim@samsung.com>
Thu, 11 Oct 2018 01:37:12 +0000 (10:37 +0900)
committersooyeon.kim <sooyeon.kim@samsung.com>
Thu, 11 Oct 2018 01:37:12 +0000 (10:37 +0900)
Change-Id: I15087eaa8dfc7e042f7c6fbb385b78f478087503
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
client/vc_widget_dbus.c

index d71d479..4cd4b9d 100644 (file)
 */
 
 
+#include <pthread.h>
+
 #include "vc_main.h"
 #include "vc_widget_client.h"
 #include "vc_widget_dbus.h"
 
 
+static pthread_mutex_t g_w_dbus_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 static int g_w_waiting_time = 3000;
 
 static Ecore_Fd_Handler* g_w_fd_handler = NULL;
@@ -286,8 +290,11 @@ static void __vc_widget_dbus_connection_free()
 
 int vc_widget_dbus_open_connection()
 {
+       pthread_mutex_lock(&g_w_dbus_mutex);
+
        if (NULL != g_w_conn_sender && NULL != g_w_conn_listener) {
                SLOG(LOG_WARN, TAG_VCW, "Already existed connection ");
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return 0;
        }
 
@@ -307,6 +314,7 @@ int vc_widget_dbus_open_connection()
 
        if (NULL == g_w_conn_sender) {
                SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -322,6 +330,7 @@ int vc_widget_dbus_open_connection()
        if (NULL == g_w_conn_listener) {
                SLOG(LOG_ERROR, TAG_VCW, "Fail to get dbus connection ");
                __vc_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -346,12 +355,14 @@ 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_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return -2;
        }
 
        if (NULL != g_w_fd_handler) {
                SLOG(LOG_WARN, TAG_VCW, "The handler already exists.");
                __vc_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return 0;
        }
 
@@ -365,6 +376,7 @@ int vc_widget_dbus_open_connection()
                SLOG(LOG_ERROR, TAG_VCW, "Match Error (%s)", err.message);
                dbus_error_free(&err);
                __vc_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
@@ -372,6 +384,7 @@ int vc_widget_dbus_open_connection()
        if (1 != dbus_connection_get_unix_fd(g_w_conn_listener, &fd)) {
                SLOG(LOG_ERROR, TAG_VCW, "fail to get fd from dbus ");
                __vc_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return VC_ERROR_OPERATION_FAILED;
        } else {
                SLOG(LOG_DEBUG, TAG_VCW, "Get fd from dbus : %d", fd);
@@ -382,14 +395,18 @@ 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_widget_dbus_connection_free();
+               pthread_mutex_unlock(&g_w_dbus_mutex);
                return VC_ERROR_OPERATION_FAILED;
        }
 
+       pthread_mutex_unlock(&g_w_dbus_mutex);
        return 0;
 }
 
 int vc_widget_dbus_close_connection()
 {
+       pthread_mutex_lock(&g_w_dbus_mutex);
+
        DBusError err;
        dbus_error_init(&err);
 
@@ -415,6 +432,8 @@ int vc_widget_dbus_close_connection()
 
        __vc_widget_dbus_connection_free();
 
+       pthread_mutex_unlock(&g_w_dbus_mutex);
+
        return 0;
 }