diff options
author | наб <[email protected]> | 2021-04-03 12:09:24 +0200 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-04-14 13:19:49 -0700 |
commit | 55780d8ec0bc1f0bc7bb4d0ae83453197e4a8556 (patch) | |
tree | 02ed16f51a52f370d7673bedeb9796fe7039ca4e | |
parent | b3a7e6e7f333292a25b6a50b6d32944c9e471cfb (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 <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #11834
-rw-r--r-- | cmd/zed/zed_file.c | 8 |
1 files changed, 1 insertions, 7 deletions
diff --git a/cmd/zed/zed_file.c b/cmd/zed/zed_file.c index 401ab89eb..0e7086d9e 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> @@ -119,9 +118,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; @@ -134,11 +131,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); |