Skip to content

Commit

Permalink
o use readdir_r() - looks like readdir is indeed not really multi-thread
Browse files Browse the repository at this point in the history
  aware.
  • Loading branch information
hzeller committed Sep 29, 2012
1 parent 11c2493 commit bf030af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -6,7 +6,7 @@ F_VERSION=$(shell git log -n1 --date=short --format="%cd (commit=%h)" 2>/dev/nul
CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -O2 -DFOLVE_VERSION='"$(F_VERSION)"' CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -O2 -DFOLVE_VERSION='"$(F_VERSION)"'


CXXFLAGS=$(CFLAGS) CXXFLAGS=$(CFLAGS)
LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd -lboost_thread-mt -lfftw3f LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd -lfftw3f


ifdef LINK_STATIC ifdef LINK_STATIC
# static linking requires us to be much more explicit when linking # static linking requires us to be much more explicit when linking
Expand Down
7 changes: 6 additions & 1 deletion folve-main.cc
Expand Up @@ -86,7 +86,11 @@ static int folve_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
if (dp == NULL) if (dp == NULL)
return -errno; return -errno;


while ((de = readdir(dp)) != NULL) { // Entry size is a bit shaky to calculate, but this should be the upper bound.
const size_t entry_size = sizeof(struct dirent) + PATH_MAX;
struct dirent *entry_buf = (struct dirent *) malloc(entry_size);

while (readdir_r(dp, entry_buf, &de) == 0 && de != NULL) {
struct stat st; struct stat st;
memset(&st, 0, sizeof(st)); memset(&st, 0, sizeof(st));
st.st_ino = de->d_ino; st.st_ino = de->d_ino;
Expand All @@ -95,6 +99,7 @@ static int folve_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
if (filler(buf, entry_name, &st, 0)) if (filler(buf, entry_name, &st, 0))
break; break;
} }
free(entry_buf);


closedir(dp); closedir(dp);
return 0; return 0;
Expand Down

0 comments on commit bf030af

Please sign in to comment.