From 65a7814b2dbc10ea86610092f03d0c1df95d08ad Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 23 May 2024 14:28:02 -0400 Subject: opt: Don't raise RLIMIT_NOFILE if it would prevent using posix_spawn() If we raise RLIMIT_NOFILE, we have to lower it before calling exec() for compatibility with select(). If posix_spawn() doesn't support that, we fall back to fork(), which is quite a bit slower. Therefore, if we're going to exec() on most files, it's better to keep RLIMIT_NOFILE the same to avoid the fork() cost, even though it makes bftw() somewhat slower. --- src/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/eval.c') diff --git a/src/eval.c b/src/eval.c index 2ca4a1f..8863e34 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1466,6 +1466,9 @@ done: static int raise_fdlimit(struct bfs_ctx *ctx) { rlim_t cur = ctx->orig_nofile.rlim_cur; rlim_t max = ctx->orig_nofile.rlim_max; + if (!ctx->raise_nofile) { + max = cur; + } rlim_t target = 64 << 10; if (rlim_cmp(target, max) > 0) { -- cgit v1.2.3