diff --git a/rpmio/cloexec.c b/rpmio/cloexec.c index 16c1e64fdd..5b0a216818 100644 --- a/rpmio/cloexec.c +++ b/rpmio/cloexec.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "rpmutil.h" static void set_cloexec(int fd) @@ -39,7 +40,13 @@ void rpmSetCloseOnExec(void) fallback: // iterate over all possible fds - int open_max = sysconf(_SC_OPEN_MAX); + struct rlimit rl; + int open_max; + + if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_max != RLIM_INFINITY) + open_max = rl.rlim_max; + else + open_max = sysconf(_SC_OPEN_MAX); if (open_max == -1) { open_max = 1024; }