Fix engine parser to access directories 95/123395/1
authorsooyeon.kim <sooyeon.kim@samsung.com>
Fri, 20 Jan 2017 07:37:45 +0000 (16:37 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Wed, 5 Apr 2017 10:22:12 +0000 (03:22 -0700)
Change-Id: I5d832f4a5715823aff37dc001d46c221a98f0e74
Signed-off-by: sooyeon.kim <sooyeon.kim@samsung.com>
(cherry picked from commit 7182e71ccfbd807230f99c9a4fbe73cc49511da2)

engine-parser/src/stt-engine-parser.c

index ecf2ba0..281818c 100644 (file)
@@ -24,6 +24,7 @@
 #include <pkgmgr_installer_info.h>
 #include <stdio.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
 #include <systemd/sd-login.h>
@@ -161,9 +162,11 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
        LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
 
        /* 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);
@@ -176,16 +179,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);
@@ -198,16 +203,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);
@@ -220,16 +227,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);
@@ -242,7 +251,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");
                        }