change the location of mutex 00/305900/2
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 13 Feb 2024 06:22:37 +0000 (15:22 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Wed, 14 Feb 2024 09:00:42 +0000 (18:00 +0900)
Before calling global variable, it calls mutex lock first.
Some cases missed that, so it changed.
And, in that case, it doesn't have to check the variable value again. So, it removed that checking condition.

Change-Id: I6e585eaad94567ef629ff878d341cf1189d648ab

client/vc.c
client/vc_mgr.c
client/vc_mgr_data.cpp
common/vc_command.c
server/vce.c

index c514b81..39bd7aa 100644 (file)
@@ -152,39 +152,39 @@ static void __check_privilege_deinitialize()
 
 static int __vc_check_privilege()
 {
-       if (true == g_privilege_allowed)
-               return VC_ERROR_NONE;
-
        pthread_mutex_lock(&g_cynara_mutex);
 
-       if (false == g_privilege_allowed) {
-               bool ret = true;
-               ret = __check_privilege_initialize();
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed");
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       if (true == g_privilege_allowed) {
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_NONE;
+       }
 
-               char uid[32];
-               snprintf(uid, 32, "%d", getuid());
-               ret = true;
-               ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed");
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
+       char uid[32];
+       snprintf(uid, 32, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
                __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
        }
 
+       __check_privilege_deinitialize();
+
        g_privilege_allowed = true;
        pthread_mutex_unlock(&g_cynara_mutex);
        return VC_ERROR_NONE;
@@ -204,39 +204,39 @@ int __check_feature_privilege()
 
 int __vc_tts_check_privilege()
 {
-       if (true == g_vc_tts_privilege_allowed)
-               return VC_ERROR_NONE;
-
        pthread_mutex_lock(&g_cynara_mutex);
 
-       if (false == g_vc_tts_privilege_allowed) {
-               bool ret = true;
-               ret = __check_privilege_initialize();
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed");
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       if (true == g_vc_tts_privilege_allowed) {
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_NONE;
+       }
 
-               char uid[32];
-               snprintf(uid, 32, "%d", getuid());
-               ret = true;
-               ret = __check_privilege(uid, VC_TTS_PRIVILEGE);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied(%s)(%s)", VC_TTS_PRIVILEGE, uid);
-                       __check_privilege_deinitialize();
-                       g_vc_tts_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] privilege initialize is failed");
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
+       char uid[32];
+       snprintf(uid, 32, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, VC_TTS_PRIVILEGE);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Permission is denied(%s)(%s)", VC_TTS_PRIVILEGE, uid);
                __check_privilege_deinitialize();
+               g_vc_tts_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
        }
 
+       __check_privilege_deinitialize();
+
        g_vc_tts_privilege_allowed = true;
        pthread_mutex_unlock(&g_cynara_mutex);
        return VC_ERROR_NONE;
index 73d5c6b..c0e5305 100644 (file)
@@ -198,51 +198,51 @@ static void __check_privilege_deinitialize()
 
 static int __vc_mgr_check_privilege()
 {
-       if (true == g_privilege_allowed)
-               return VC_ERROR_NONE;
-
        pthread_mutex_lock(&g_cynara_mutex);
 
-       if (false == g_privilege_allowed) {
-               bool ret = true;
-               ret = __check_privilege_initialize();
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCM, "[ERROR] privilege initialize is failed");
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       if (true == g_privilege_allowed) {
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_NONE;
+       }
 
-               char uid[32];
-               snprintf(uid, 32, "%d", getuid());
-               ret = true;
-               ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] privilege initialize is failed");
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
-               ret = __check_privilege(uid, VC_MGR_PRIVILEGE);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_MGR_PRIVILEGE, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       char uid[32];
+       snprintf(uid, 32, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
+               __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
+       ret = __check_privilege(uid, VC_MGR_PRIVILEGE);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCM, "[ERROR] Permission is denied(%s)(%s)", VC_MGR_PRIVILEGE, uid);
                __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
        }
 
+       __check_privilege_deinitialize();
+
        g_privilege_allowed = true;
        pthread_mutex_unlock(&g_cynara_mutex);
        return VC_ERROR_NONE;
index 27c96a2..cdcffdc 100644 (file)
@@ -96,10 +96,10 @@ int vc_mgr_data_get_feedback_data_size()
 
 int vc_mgr_data_clear_feedback_data(vc_feedback_data_s** data)
 {
-       SLOG(LOG_INFO, TAG_VCM, "[DATA] clear feedback data, empty(%d)", g_feedback_data.empty());
-
        pthread_mutex_lock(&g_feedback_data_mutex);
 
+       SLOG(LOG_INFO, TAG_VCM, "[DATA] clear feedback data, empty(%d)", g_feedback_data.empty());
+
        if (NULL != *data) {
                SLOG(LOG_INFO, TAG_VCM, "[DEBUG] pid(%d), utt_id(%d), data(%p) size(%d) rate(%d)", (*data)->pid, (*data)->utt_id, (*data)->data, (*data)->data_size, (*data)->rate);
 
index edff3b4..2958d9d 100644 (file)
@@ -150,38 +150,38 @@ static void __check_privilege_deinitialize()
 
 static int __vc_cmd_check_privilege()
 {
-       if (true == g_privilege_allowed)
-               return VC_ERROR_NONE;
-
        pthread_mutex_lock(&g_cynara_mutex);
 
-       if (false == g_privilege_allowed) {
-               bool ret = true;
-               ret = __check_privilege_initialize();
-               if (false == ret) {
-                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-               }
+       if (true == g_privilege_allowed) {
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_NONE;
+       }
 
-               char uid[32];
-               snprintf(uid, 32, "%d", getuid());
-               ret = true;
-               ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VC_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] privilege initialize is failed");
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+       }
 
+       char uid[32];
+       snprintf(uid, 32, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCCMD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
                __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
        }
 
+       __check_privilege_deinitialize();
+
        g_privilege_allowed = true;
        pthread_mutex_unlock(&g_cynara_mutex);
        return VC_ERROR_NONE;
index 7daff10..d97cb86 100644 (file)
@@ -113,60 +113,59 @@ static void __check_privilege_deinitialize()
 
 static int __vce_check_privilege()
 {
-       if (true == g_privilege_allowed)
-               return VC_ERROR_NONE;
-
        pthread_mutex_lock(&g_cynara_mutex);
 
-       if (false == g_privilege_allowed) {
-               bool ret = true;
-               ret = __check_privilege_initialize();
-               if (false == ret) {
-                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] privilege initialize is failed");
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VCE_ERROR_PERMISSION_DENIED;
-               }
-
-               char uid[32];
-               snprintf(uid, 32, "%d", getuid());
-               ret = true;
-               ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VCE_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       if (true == g_privilege_allowed) {
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VC_ERROR_NONE;
+       }
 
-               ret = __check_privilege(uid, VC_PRIVILEGE_APPMGR_LAUNCH);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_APPMGR_LAUNCH, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VCE_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] privilege initialize is failed");
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VCE_ERROR_PERMISSION_DENIED;
+       }
 
-               ret = __check_privilege(uid, VC_PRIVILEGE_DATASHARING);
-               if (false == ret) {
-                       //LCOV_EXCL_START
-                       SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_DATASHARING, uid);
-                       __check_privilege_deinitialize();
-                       g_privilege_allowed = false;
-                       pthread_mutex_unlock(&g_cynara_mutex);
-                       return VCE_ERROR_PERMISSION_DENIED;
-                       //LCOV_EXCL_STOP
-               }
+       char uid[32];
+       snprintf(uid, 32, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, VC_PRIVILEGE_RECORDER);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_RECORDER, uid);
+               __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VCE_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
+       ret = __check_privilege(uid, VC_PRIVILEGE_APPMGR_LAUNCH);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_APPMGR_LAUNCH, uid);
                __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VCE_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
+       }
 
+       ret = __check_privilege(uid, VC_PRIVILEGE_DATASHARING);
+       if (false == ret) {
+               //LCOV_EXCL_START
+               SLOG(LOG_ERROR, TAG_VCD, "[ERROR] Permission is denied(%s)(%s)", VC_PRIVILEGE_DATASHARING, uid);
+               __check_privilege_deinitialize();
+               g_privilege_allowed = false;
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return VCE_ERROR_PERMISSION_DENIED;
+               //LCOV_EXCL_STOP
        }
 
+       __check_privilege_deinitialize();
+
        g_privilege_allowed = true;
        pthread_mutex_unlock(&g_cynara_mutex);
        return VCE_ERROR_NONE;