Skip to content

Commit

Permalink
zed: only go up to current limit in close_from() fallback
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nabijaczleweli authored and tonyhutter committed Nov 1, 2021
1 parent 10b8156 commit 61788f4
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions cmd/zed/zed_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 61788f4

Please sign in to comment.