From 55780d8ec0bc1f0bc7bb4d0ae83453197e4a8556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 3 Apr 2021 12:09:24 +0200 Subject: [PATCH] zed: only go up to current limit in close_from() fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Ahelenia ZiemiaƄska Closes #11834 --- cmd/zed/zed_file.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/zed/zed_file.c b/cmd/zed/zed_file.c index 401ab89eb4f2..0e7086d9e8ca 100644 --- a/cmd/zed/zed_file.c +++ b/cmd/zed/zed_file.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -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);