summaryrefslogtreecommitdiffstats
path: root/exec.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-05-20 13:03:31 -0400
committerTavian Barnes <tavianator@tavianator.com>2021-05-20 16:33:17 -0400
commit69a5227098b87b048a90ceb1ca7b169c02ba151e (patch)
tree088c97c93c4f36c0d128a817dfc372704033f14a /exec.c
parentb08424dd960c2241ce14a61c0241c90f612cd6b4 (diff)
downloadbfs-69a5227098b87b048a90ceb1ca7b169c02ba151e.tar.xz
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()).
Diffstat (limited to 'exec.c')
-rw-r--r--exec.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/exec.c b/exec.c
index 2856071..bc01808 100644
--- a/exec.c
+++ b/exec.c
@@ -30,6 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/resource.h>
#include <sys/wait.h>
#include <unistd.h>
@@ -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;