Fix engine parser to access directories 95/117795/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Fri, 20 Jan 2017 07:48:33 +0000 (16:48 +0900)
committerWonnam Jang <wn.jang@samsung.com>
Tue, 7 Mar 2017 11:56:18 +0000 (03:56 -0800)
Change-Id: I05cdbaaadfa8d2dcd66968039b1f238939f736f4
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 80c1341fdc55109bd7b092b80ad2383c733605f1)

engine-parser/src/tts-engine-parser.c

index 68786dc..ca8f5e7 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <fcntl.h>
 #include <tzplatform_config.h>
 #include <systemd/sd-login.h>
 
@@ -162,9 +163,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
 
 
        /* Make directories */
-       if (0 != access(dir_config_base, F_OK)) {
+//     if (0 != access(dir_config_base, F_OK)) {
+       if (-1 == open(dir_config_base, O_DIRECTORY)) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
                if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_config_base);
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
                        free(dir_config_base);
                        dir_config_base = NULL;
                        free(dir_home);
@@ -177,16 +180,18 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                } else {
                        LOGD("Success to make directory : %s", dir_config_base);
                        if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
        }
 
-       if (0 != access(dir_home, F_OK)) {
+//     if (0 != access(dir_home, F_OK)) {
+       if (-1 == open(dir_home, O_DIRECTORY)) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
                if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_home);
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
                        free(dir_config_base);
                        dir_config_base = NULL;
                        free(dir_home);
@@ -199,16 +204,18 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                } else {
                        LOGD("Success to make directory : %s", dir_home);
                        if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
        }
 
-       if (0 != access(dir_engine_base, F_OK)) {
+//     if (0 != access(dir_engine_base, F_OK)) {
+       if (-1 == open(dir_engine_base, O_DIRECTORY)) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
                if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_base);
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
                        free(dir_config_base);
                        dir_config_base = NULL;
                        free(dir_home);
@@ -221,16 +228,18 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                } else {
                        LOGD("Success to make directory : %s", dir_engine_base);
                        if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
        }
 
-       if (0 != access(dir_engine_info, F_OK)) {
+//     if (0 != access(dir_engine_info, F_OK)) {
+       if (-1 == open(dir_engine_info, O_DIRECTORY)) {
+               LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
                if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
-                       LOGE("[ERROR] Fail to make directory : %s", dir_engine_info);
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
                        free(dir_config_base);
                        dir_config_base = NULL;
                        free(dir_home);
@@ -243,7 +252,7 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                } else {
                        LOGD("Success to make directory : %s", dir_engine_info);
                        if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }