diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-06-03 13:34:15 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-06-03 13:34:15 -0400 |
commit | 8b55d62f4ec9739884e75feeba785014db71aca5 (patch) | |
tree | eee2b6595177cdb10cfd4d6b45750aff33c72558 | |
parent | bd419aca16f0d3cafcb13b386a5bcab7428e4009 (diff) | |
download | bfs-8b55d62f4ec9739884e75feeba785014db71aca5.tar.xz |
eval: Clean up open fd counting code.
-rw-r--r-- | eval.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -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; } |