summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2021-04-03 12:09:24 +0200
committerTony Hutter <hutter2@llnl.gov>2021-11-01 16:10:09 -0700
commit61788f4f5eba130d230c8ebd38184a2c39e5433e (patch)
tree2f6a2952ec31f51295725d0557bf2dd6e4b73b11
parent10b81561aa91d31a0dfcc77cdb8e5b367a71a7d0 (diff)
zed: only go up to current limit in close_from() fallback
Consider the following strace log: prlimit64(0, RLIMIT_NOFILE, NULL, {rlim_cur=1024, rlim_max=1024*1024}) = 0 dup2(0, 30) = 30 dup2(0, 300) = 300 dup2(0, 3000) = -1 EBADF (Bad file descriptor) dup2(0, 30000) = -1 EBADF (Bad file descriptor) dup2(0, 300000) = -1 EBADF (Bad file descriptor) prlimit64(0, RLIMIT_NOFILE, {rlim_cur=1024*1024, rlim_max=1024*1024}, NULL) = 0 dup2(0, 30) = 30 dup2(0, 300) = 300 dup2(0, 3000) = 3000 dup2(0, 30000) = 30000 dup2(0, 300000) = 300000 Even a privileged process needs to bump its rlimit before being able to use fds higher than rlim_cur. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11834
-rw-r--r--cmd/zed/zed_file.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/cmd/zed/zed_file.c b/cmd/zed/zed_file.c
index 6b6a56759..2212022ef 100644
--- a/cmd/zed/zed_file.c
+++ b/cmd/zed/zed_file.c
@@ -17,7 +17,6 @@
#include <fcntl.h>
#include <limits.h>
#include <string.h>
-#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -175,9 +174,7 @@ zed_file_is_locked(int fd)
void
zed_file_close_from(int lowfd)
{
- static const int maxfd_def = 256;
int errno_bak = errno;
- struct rlimit rl;
int maxfd = 0;
int fd;
DIR *fddir;
@@ -190,11 +187,8 @@ zed_file_close_from(int lowfd)
maxfd = fd;
}
(void) closedir(fddir);
- } else if (getrlimit(RLIMIT_NOFILE, &rl) < 0 ||
- rl.rlim_max == RLIM_INFINITY) {
- maxfd = maxfd_def;
} else {
- maxfd = rl.rlim_max;
+ maxfd = sysconf(_SC_OPEN_MAX);
}
for (fd = lowfd; fd < maxfd; fd++)
(void) close(fd);