From 69a5227098b87b048a90ceb1ca7b169c02ba151e Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 20 May 2021 13:03:31 -0400 Subject: eval: Raise RLIMIT_NOFILE if possible This lets us keep more open FDs cached in bftw(). The limit is lowered before running -exec commands, in case they're incompatible with a high limit (e.g. due to select()). --- ctx.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ctx.c') diff --git a/ctx.c b/ctx.c index 72ed969..b17d148 100644 --- a/ctx.c +++ b/ctx.c @@ -93,6 +93,15 @@ struct bfs_ctx *bfs_ctx_new(void) { trie_init(&ctx->files); ctx->nfiles = 0; + struct rlimit rl; + if (getrlimit(RLIMIT_NOFILE, &rl) == 0) { + ctx->nofile_soft = rl.rlim_cur; + ctx->nofile_hard = rl.rlim_max; + } else { + ctx->nofile_soft = 1024; + ctx->nofile_hard = RLIM_INFINITY; + } + return ctx; } -- cgit v1.2.3