Remove thread unsafety function usages. 80/62480/7 accepted/tizen/common/20160317.161902 accepted/tizen/ivi/20160318.113739 accepted/tizen/mobile/20160318.113526 accepted/tizen/tv/20160318.113623 accepted/tizen/wearable/20160318.113603 submit/tizen/20160317.122246
authorpr.jung <pr.jung@samsung.com>
Wed, 16 Mar 2016 09:26:16 +0000 (18:26 +0900)
committerpr.jung <pr.jung@samsung.com>
Thu, 17 Mar 2016 09:02:40 +0000 (18:02 +0900)
- readdir - > readdir_r

Change-Id: I742e48f190e1b77416fd6a71971faf2b27e2fd92
Signed-off-by: pr.jung <pr.jung@samsung.com>
src/shared/util.c
src/shared/util.h

index 969a97808e0d8bef429037440af6a919db03d074..eed0476945d4d0a38277facccf91a7a31a67a253 100644 (file)
@@ -96,7 +96,7 @@ int system_command_with_timeout(int timeout_seconds, char *command)
                argv[3] = 0;
 
                execve("/bin/sh", argv, (char **)environ);
-               _SI("exec(%s): %s\n", command, strerror(errno));
+               _SI("exec(%s): %d\n", command, errno);
                _exit(-1);
        }
        /* handle parent case */
@@ -293,13 +293,17 @@ int run_command_write_fd(char *cmd, int dfd)
 static int remove_dir_internal(int fd)
 {
        DIR *dir;
+       struct dirent e;
        struct dirent *de;
        int subfd, ret = 0;
 
        dir = fdopendir(fd);
        if (!dir)
                return -1;
-       while ((de = readdir(dir))) {
+
+       if ((readdir_r(dir, &e, &de)) != 0)
+               de = NULL;
+       while (de) {
                if (de->d_type == DT_DIR) {
                        if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
                                continue;
@@ -314,12 +318,12 @@ static int remove_dir_internal(int fd)
                        }
                        close(subfd);
                        if (unlinkat(fd, de->d_name, AT_REMOVEDIR) < 0) {
-                               _SE("Couldn't unlinkat %s: %s\n", de->d_name, strerror(errno));
+                               _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
                                ret = -1;
                        }
                } else {
                        if (unlinkat(fd, de->d_name, 0) < 0) {
-                               _SE("Couldn't unlinkat %s: %s\n", de->d_name, strerror(errno));
+                               _SE("Couldn't unlinkat %s: %d\n", de->d_name, errno);
                                ret = -1;
                        }
                }
@@ -336,7 +340,7 @@ int remove_dir(const char *path, int del_dir)
                return -1;
        fd = open(path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
        if (fd < 0) {
-               _SE("Couldn't opendir %s: %s\n", path, strerror(errno));
+               _SE("Couldn't opendir %s: %d\n", path, errno);
                return -errno;
        }
        ret = remove_dir_internal(fd);
@@ -344,42 +348,17 @@ int remove_dir(const char *path, int del_dir)
 
        if (del_dir) {
                if (rmdir(path)) {
-                       _SE("Couldn't rmdir %s: %s\n", path, strerror(errno));
+                       _SE("Couldn't rmdir %s: %d\n", path, errno);
                        ret = -1;
                }
        }
        return ret;
 }
 
-int make_dir(const char *path, mode_t mode, const char *grname)
-{
-       mode_t old_mask;
-       struct group *group_entry;
-       int ret;
-
-       if (!grname || !path)
-               return -1;
-       if (access(path, F_OK) == 0)
-               return 0;
-       old_mask = umask(002);
-       ret = mkdir(path, mode);
-       if (ret < 0)
-               return -1;
-       group_entry = getgrnam(grname);
-       if (group_entry == NULL) {
-               umask(old_mask);
-               return -1;
-       }
-       if (chown(path, 0, group_entry->gr_gid) < 0)
-               _SW("can't chown (%s)\n", path);
-       umask(old_mask);
-
-       return 0;
-}
-
 int get_exec_pid(const char *execpath)
 {
        DIR *dp;
+       struct dirent entry;
        struct dirent *dentry;
        int pid = -1, fd;
        int ret;
@@ -394,7 +373,10 @@ int get_exec_pid(const char *execpath)
        }
 
        len = strlen(execpath) + 1;
-       while ((dentry = readdir(dp)) != NULL) {
+       if ((readdir_r(dp, &entry, &dentry)) != 0)
+               dentry = NULL;
+
+       while (dentry != NULL) {
                if (!isdigit(dentry->d_name[0]))
                        continue;
 
@@ -426,13 +408,18 @@ int get_exec_pid(const char *execpath)
 int get_file_count(char *path)
 {
        DIR *dir;
+       struct dirent p;
        struct dirent *dp;
        int count = 0;
 
        dir = opendir(path);
        if (!dir)
                return 0;
-       while ((dp = readdir(dir)) != NULL) {
+
+       if ((readdir_r(dir, &p, &dp)) != 0)
+               dp = NULL;
+
+       while (dp != NULL) {
                const char *name = dp->d_name;
                /* always skip "." and ".." */
                if (name[0] == '.') {
@@ -450,6 +437,7 @@ int get_file_count(char *path)
 int get_directory_usage(char *path)
 {
        DIR *dir;
+       struct dirent e;
        struct dirent *de;
        struct stat st;
        size_t usage = 0;
@@ -463,11 +451,15 @@ int get_directory_usage(char *path)
                close(fd);
                return -1;
        }
-       while ((de = readdir(dir))) {
+
+       if ((readdir_r(dir, &e, &de)) != 0)
+               de = NULL;
+
+       while (de) {
                if (!strncmp(de->d_name, ".", 2) || !strncmp(de->d_name, "..", 3))
                        continue;
                if (fstatat(fd, de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0) {
-                       _SE("Failed to fstatat  %s: %s\n", de->d_name, strerror(errno));
+                       _SE("Failed to fstatat  %s: %d\n", de->d_name, errno);
                        continue;
                }
                usage += st.st_size;
index 299e616e4ad8bf8e3fb5efc0b663e281cbe1439d..2efa1082b5560670ae4ecf3d00938c2c12fce667 100644 (file)
@@ -41,8 +41,6 @@ int dump_file_write_fd(char *src, int dfd);
 
 int run_command_write_fd(char *cmd, int dfd);
 
-int make_dir(const char *path, mode_t mode, const char *grname);
-
 int remove_dir(const char *path, int del_dir);
 
 int get_exec_pid(const char *execpath);