diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2015-07-27 16:31:35 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2015-07-27 16:31:35 -0400 |
commit | e7cb622ee5cf2cc1c019374c3911d9c70083701d (patch) | |
tree | f6ac4d57dab272c69cb66c1fcd93082973334603 /bftw.c | |
parent | 781f5902b7bbb91811f1f810f8a419607ed36294 (diff) | |
download | bfs-e7cb622ee5cf2cc1c019374c3911d9c70083701d.tar.xz |
Infer the right value for nopenfd, and recover from EMFILE.
Diffstat (limited to 'bftw.c')
-rw-r--r-- | bftw.c | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -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); |