[PATCH v2] ntdll: Use the true maximum open FDs to set the limit on Mac.
The actual upper limit is stored in the sysctl(3) "kern.maxfilesperproc". This value may be higher than the value of the OPEN_MAX constant. Using sysconf(3) with _SC_OPEN_MAX just returns the current value of RLIMIT_NOFILE, so that won't work here. Signed-off-by: Chip Davis <cdavis5x(a)gmail.com> --- v2: Remove unnecessary #ifdefs. --- dlls/ntdll/unix/loader.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index d5867e4aa754..0617fca631c1 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -452,13 +452,23 @@ static void set_max_limit( int limit ) rlimit.rlim_cur = rlimit.rlim_max; if (setrlimit( limit, &rlimit ) != 0) { -#if defined(__APPLE__) && defined(RLIMIT_NOFILE) && defined(OPEN_MAX) - /* On Leopard, setrlimit(RLIMIT_NOFILE, ...) fails on attempts to set - * rlim_cur above OPEN_MAX (even if rlim_max > OPEN_MAX). */ - if (limit == RLIMIT_NOFILE && rlimit.rlim_cur > OPEN_MAX) +#if defined(__APPLE__) && defined(RLIMIT_NOFILE) + if (limit == RLIMIT_NOFILE) { - rlimit.rlim_cur = OPEN_MAX; - setrlimit( limit, &rlimit ); + /* On Leopard, setrlimit(RLIMIT_NOFILE, ...) fails on attempts to set + * rlim_cur above OPEN_MAX (even if rlim_max > OPEN_MAX). */ + int open_max; + /* This is the true OPEN_MAX; it may be greater than the constant. + * sysconf(_SC_OPEN_MAX) won't work here: it just returns getrlimit(RLIMIT_NOFILE). */ + static int maxfilesperproc_oid[] = { CTL_KERN, KERN_MAXFILESPERPROC }; + size_t len = sizeof(open_max); + if (sysctl( maxfilesperproc_oid, ARRAY_SIZE(maxfilesperproc_oid), &open_max, &len, NULL, 0 ) != 0) + open_max = OPEN_MAX; + if (rlimit.rlim_cur > open_max) + { + rlimit.rlim_cur = open_max; + setrlimit( limit, &rlimit ); + } } #endif } -- 2.34.1
Hi, While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=112888 Your paranoid android. === debian11 (64 bit WoW report) === ntdll: env.c:461: Test failed: wrong end ptr 000000000003197C/0000000000031980
participants (2)
-
Chip Davis -
Marvin