summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2015-07-27 16:31:35 -0400
committerTavian Barnes <tavianator@tavianator.com>2015-07-27 16:31:35 -0400
commite7cb622ee5cf2cc1c019374c3911d9c70083701d (patch)
treef6ac4d57dab272c69cb66c1fcd93082973334603 /bftw.c
parent781f5902b7bbb91811f1f810f8a419607ed36294 (diff)
downloadbfs-e7cb622ee5cf2cc1c019374c3911d9c70083701d.tar.xz
Infer the right value for nopenfd, and recover from EMFILE.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/bftw.c b/bftw.c
index 31e6fe2..75a208c 100644
--- a/bftw.c
+++ b/bftw.c
@@ -291,7 +291,19 @@ static DIR *dircache_entry_open(dircache *cache, dircache_entry *entry, const ch
fd = dirfd(base->dir);
}
- DIR *dir = opendirat(fd, path + nameoff);
+ const char *relpath = path + nameoff;
+ DIR *dir = opendirat(fd, relpath);
+
+ if (!dir
+ && errno == EMFILE
+ && cache->lru_tail
+ && cache->lru_tail != base) {
+ // Too many open files, shrink the LRU cache
+ dircache_entry_close(cache, cache->lru_tail);
+ --cache->lru_remaining;
+ dir = opendirat(fd, relpath);
+ }
+
if (dir) {
entry->dir = dir;
dircache_lru_add(cache, entry);