From bf030afb4c0fe8c4e9fe1a64b048ac13b17334f7 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Sat, 29 Sep 2012 09:07:22 -0700 Subject: [PATCH] o use readdir_r() - looks like readdir is indeed not really multi-thread aware. --- Makefile | 2 +- folve-main.cc | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5ae8074..582404d 100644 --- a/Makefile +++ b/Makefile @@ -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)"' CXXFLAGS=$(CFLAGS) -LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd -lboost_thread-mt -lfftw3f +LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd -lfftw3f ifdef LINK_STATIC # static linking requires us to be much more explicit when linking diff --git a/folve-main.cc b/folve-main.cc index e74ba04..e0493ce 100644 --- a/folve-main.cc +++ b/folve-main.cc @@ -86,7 +86,11 @@ static int folve_readdir(const char *path, void *buf, fuse_fill_dir_t filler, if (dp == NULL) 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; memset(&st, 0, sizeof(st)); st.st_ino = de->d_ino; @@ -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)) break; } + free(entry_buf); closedir(dp); return 0;