Fixed cynara code. 17/220017/4
authorsungrae jo <seongrae.jo@samsung.com>
Fri, 13 Dec 2019 02:11:18 +0000 (11:11 +0900)
committersungrae jo <seongrae.jo@samsung.com>
Fri, 13 Dec 2019 02:22:23 +0000 (11:22 +0900)
Change-Id: Ic07a73231e5a2af8c3d8173e1dcaeb07c7d3dfbd
Signed-off-by: sungrae jo <seongrae.jo@samsung.com>
client/stt.c

index 8bf8bc1..99ce8ac 100644 (file)
@@ -44,8 +44,7 @@ static float g_volume_db = 0;
 
 static int g_feature_enabled = -1;
 
-static int g_privilege_allowed = -1;
-static int g_privilege_applaunch_allowed = -1;
+static pthread_mutex_t g_cynara_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static cynara *p_cynara = NULL;
 
@@ -150,53 +149,55 @@ static void __check_privilege_deinitialize()
 
 static int __stt_check_privilege()
 {
-       char uid[16];
+       pthread_mutex_lock(&g_cynara_mutex);
+
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return STT_ERROR_PERMISSION_DENIED;
+       }
 
-       if (0 == g_privilege_allowed) {
+       char uid[16];
+       snprintf(uid, 16, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, STT_PRIVILEGE_RECORDER);
+       __check_privilege_deinitialize();
+       if (false == ret) {
                SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&g_cynara_mutex);
                return STT_ERROR_PERMISSION_DENIED;
-       } else if (-1 == g_privilege_allowed) {
-               if (false == __check_privilege_initialize()) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
-                       return STT_ERROR_PERMISSION_DENIED;
-               }
-               snprintf(uid, 16, "%d", getuid());
-               if (false == __check_privilege(uid, STT_PRIVILEGE_RECORDER)) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied"); //LCOV_EXCL_LINE
-                       g_privilege_allowed = 0;
-                       __check_privilege_deinitialize();
-                       return STT_ERROR_PERMISSION_DENIED;
-               }
-               __check_privilege_deinitialize();
        }
 
-       g_privilege_allowed = 1;
+       pthread_mutex_unlock(&g_cynara_mutex);
        return STT_ERROR_NONE;
 }
 
 static int __stt_check_privilege_for_applaunch()
 {
-       char uid[16];
+       pthread_mutex_lock(&g_cynara_mutex);
 
-       if (0 == g_privilege_applaunch_allowed) {
-               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission for applaunch is denied"); //LCOV_EXCL_LINE
+       bool ret = true;
+       ret = __check_privilege_initialize();
+       if (false == ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&g_cynara_mutex);
+               return STT_ERROR_PERMISSION_DENIED;
+       }
+
+       char uid[16];
+       snprintf(uid, 16, "%d", getuid());
+       ret = true;
+       ret = __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH);
+       __check_privilege_deinitialize();
+       if (false == ret) {
+               SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
+               pthread_mutex_unlock(&g_cynara_mutex);
                return STT_ERROR_PERMISSION_DENIED;
-       } else if (-1 == g_privilege_applaunch_allowed) {
-               if (false == __check_privilege_initialize()) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] privilege initialize is failed (applaunch)"); //LCOV_EXCL_LINE
-                       return STT_ERROR_PERMISSION_DENIED;
-               }
-               snprintf(uid, 16, "%d", getuid());
-               if (false == __check_privilege(uid, STT_PRIVILEGE_APPLAUNCH)) {
-                       SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Permission is denied : appmanager.launch"); //LCOV_EXCL_LINE
-                       g_privilege_applaunch_allowed = 0;
-                       __check_privilege_deinitialize();
-                       return STT_ERROR_PERMISSION_DENIED;
-               }
-               __check_privilege_deinitialize();
        }
 
-       g_privilege_applaunch_allowed = 1;
+       pthread_mutex_unlock(&g_cynara_mutex);
        return STT_ERROR_NONE;
 }
 
@@ -961,7 +962,7 @@ static Eina_Bool __stt_connect_daemon(void *data)
        }
 
        /* Check and Set vconfkey of custom engine before sending hello */
-       if (1 == g_privilege_applaunch_allowed && NULL != client->current_engine_id) {
+       if (NULL != client->current_engine_id && 0 == __stt_check_privilege_for_applaunch()) {
                /* Set vconfkey */
                ret = __stt_set_buxtonkey(client->current_engine_id);
                //LCOV_EXCL_START