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()). --- exec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'exec.c') diff --git a/exec.c b/exec.c index 2856071..bc01808 100644 --- a/exec.c +++ b/exec.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -358,6 +359,15 @@ static int bfs_exec_spawn(const struct bfs_exec *execbuf) { goto fail; } + // Reset RLIMIT_NOFILE, to avoid breaking applications that use select() + struct rlimit rl = { + .rlim_cur = execbuf->ctx->nofile_soft, + .rlim_max = execbuf->ctx->nofile_hard, + }; + if (bfs_spawn_addsetrlimit(&ctx, RLIMIT_NOFILE, &rl) != 0) { + goto fail; + } + if (execbuf->wd_fd >= 0) { if (bfs_spawn_addfchdir(&ctx, execbuf->wd_fd) != 0) { goto fail; -- cgit v1.2.3