summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-06-03 13:34:15 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-06-03 13:34:15 -0400
commit8b55d62f4ec9739884e75feeba785014db71aca5 (patch)
treeeee2b6595177cdb10cfd4d6b45750aff33c72558 /eval.c
parentbd419aca16f0d3cafcb13b386a5bcab7428e4009 (diff)
downloadbfs-8b55d62f4ec9739884e75feeba785014db71aca5.tar.xz
eval: Clean up open fd counting code.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/eval.c b/eval.c
index 87c6932..9ac0c6a 100644
--- a/eval.c
+++ b/eval.c
@@ -867,14 +867,15 @@ static int infer_fdlimit() {
}
}
- // Account for std{in,out,err}, and allow an extra fd for the predicates
- int nopen = 4;
+ // std{in,out,err}
+ int nopen = 3;
// Check /dev/fd for the current number of open fds, if possible (we may
// have inherited more than just the standard ones)
DIR *dir = opendir("/dev/fd");
if (dir) {
- nopen = 0;
+ // Account for 'dir' itself
+ nopen = -1;
struct dirent *de;
while ((de = readdir(dir)) != NULL) {
@@ -886,8 +887,11 @@ static int infer_fdlimit() {
closedir(dir);
}
- if (ret > nopen) {
- ret -= nopen;
+ // Extra fd needed by -empty
+ int reserved = nopen + 1;
+
+ if (ret > reserved) {
+ ret -= reserved;
} else {
ret = 1;
}