os-posix: Expand setrlimit() syscall compatibility
authorTrent Huber <trentmhuber@gmail.com>
Fri, 14 Jun 2024 21:06:38 +0000 (17:06 -0400)
committerMichael Tokarev <mjt@tls.msk.ru>
Sun, 30 Jun 2024 16:51:44 +0000 (19:51 +0300)
Darwin uses a subtly different version of the setrlimit() syscall as
described in the COMPATIBILITY section of the macOS man page. The value
of the rlim_cur member has been adjusted accordingly for Darwin-based
systems.

Signed-off-by: Trent Huber <trentmhuber@gmail.com>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
os-posix.c

index a4284e2c07bb7f276dfb7f3cfdec133fb76ff4cd..43f9a43f3fe2cdf6205e18075fcd48764c993db7 100644 (file)
@@ -270,7 +270,11 @@ void os_setup_limits(void)
         return;
     }
 
+#ifdef CONFIG_DARWIN
+    nofile.rlim_cur = OPEN_MAX < nofile.rlim_max ? OPEN_MAX : nofile.rlim_max;
+#else
     nofile.rlim_cur = nofile.rlim_max;
+#endif
 
     if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
         warn_report("unable to set NOFILE limit: %s", strerror(errno));