aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Pärtel <martin.partel@gmail.com>2012-05-18 16:41:36 +0300
committerMartin Pärtel <martin.partel@gmail.com>2012-05-18 16:41:36 +0300
commite36a87e1cf4ece334ce16c99877d0640e2743dfa (patch)
treedc567b1ed2373da112b3d55d0bf54e3fe0534f3e /src
parentb5287339fa2196f8741cf0a23e5c83e0772c46e9 (diff)
downloadbindfs-e36a87e1cf4ece334ce16c99877d0640e2743dfa.tar.gz
Use readdir_r() for thread-safety.
Diffstat (limited to 'src')
-rw-r--r--src/bindfs.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/bindfs.c b/src/bindfs.c
index b0cd9a0..5d7974d 100644
--- a/src/bindfs.c
+++ b/src/bindfs.c
@@ -31,7 +31,7 @@
#include <config.h>
-/* For pread/pwrite */
+/* For pread/pwrite and readdir_r */
#define _XOPEN_SOURCE 500
#include <stdlib.h>
@@ -395,12 +395,25 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
DIR *dp = get_dirp(fi);
+ struct dirent *de_buf;
struct dirent *de;
+ struct stat st;
+ int result = 0;
(void) path;
+ de_buf = malloc(offsetof(struct dirent, d_name) + pathconf(path, _PC_NAME_MAX) + 1);
+
seekdir(dp, offset);
- while ((de = readdir(dp)) != NULL) {
- struct stat st;
+ while (1) {
+ result = readdir_r(dp, de_buf, &de);
+ if (result != 0) {
+ result = -result;
+ break;
+ }
+ if (de == NULL) {
+ break;
+ }
+
memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
@@ -408,7 +421,8 @@ static int bindfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
break;
}
- return 0;
+ free(de_buf);
+ return result;
}
static int bindfs_releasedir(const char *path, struct fuse_file_info *fi)