diff mbox series

os-posix: Expand setrlimit() syscall compatibility

Message ID 20240614051422.13532-1-trentmhuber@gmail.com
State New
Headers show
Series os-posix: Expand setrlimit() syscall compatibility | expand

Commit Message

Trent Huber June 14, 2024, 5:14 a.m. UTC
Darwin (I'm running version 19.6.0) uses a subtly different version
of the setrlimit() syscall as described in the COMPATIBILITY section
of the macOS man page. I adjusted the way the rlim_cur member is set
to accommodate and which shouldn't affect any non-Darwin systems.

Signed-off-by: Trent Huber <trentmhuber@gmail.com>
---
 os-posix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Daniel P. Berrangé June 14, 2024, 1:30 p.m. UTC | #1
On Fri, Jun 14, 2024 at 01:14:22AM -0400, Trent Huber wrote:
> Darwin (I'm running version 19.6.0) uses a subtly different version
> of the setrlimit() syscall as described in the COMPATIBILITY section
> of the macOS man page. I adjusted the way the rlim_cur member is set
> to accommodate and which shouldn't affect any non-Darwin systems.
> 
> Signed-off-by: Trent Huber <trentmhuber@gmail.com>
> ---
>  os-posix.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/os-posix.c b/os-posix.c
> index a4284e2c07..5766346521 100644
> --- a/os-posix.c
> +++ b/os-posix.c
> @@ -270,7 +270,7 @@ void os_setup_limits(void)
>          return;
>      }
>  
> -    nofile.rlim_cur = nofile.rlim_max;
> +    nofile.rlim_cur = OPEN_MAX < nofile.rlim_max ? OPEN_MAX : nofile.rlim_max;

There's no such constant OPEN_MAX on Linux, so this doesn't compile.

There is a sysconf() parameter _SC_OPEN_MAX, but we should not use
that as it is a dynamic value that just reflects what 'rlim_cur'
is set to, and would thus turn this into a no-op.

This should just be made conditional to macOS, since its the only
problematic platform that we known of.

With regards,
Daniel
Trent Huber June 14, 2024, 8:11 p.m. UTC | #2
> On Jun 14, 2024, at 9:30 AM, Daniel P. Berrangé <berrange@redhat.com> wrote:
> 
> On Fri, Jun 14, 2024 at 01:14:22AM -0400, Trent Huber wrote:
>> Darwin (I'm running version 19.6.0) uses a subtly different version
>> of the setrlimit() syscall as described in the COMPATIBILITY section
>> of the macOS man page. I adjusted the way the rlim_cur member is set
>> to accommodate and which shouldn't affect any non-Darwin systems.
>> 
>> Signed-off-by: Trent Huber <trentmhuber@gmail.com>
>> ---
>> os-posix.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/os-posix.c b/os-posix.c
>> index a4284e2c07..5766346521 100644
>> --- a/os-posix.c
>> +++ b/os-posix.c
>> @@ -270,7 +270,7 @@ void os_setup_limits(void)
>>         return;
>>     }
>> 
>> -    nofile.rlim_cur = nofile.rlim_max;
>> +    nofile.rlim_cur = OPEN_MAX < nofile.rlim_max ? OPEN_MAX : nofile.rlim_max;
> 
> There's no such constant OPEN_MAX on Linux, so this doesn't compile.
> 
> There is a sysconf() parameter _SC_OPEN_MAX, but we should not use
> that as it is a dynamic value that just reflects what 'rlim_cur'
> is set to, and would thus turn this into a no-op.
> 
> This should just be made conditional to macOS, since its the only
> problematic platform that we known of.
> 
> With regards,
> Daniel
> -- 
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Thanks for looking this over, I'll add some conditionals and send a v2 of the patch.

Kindly,
Trent
diff mbox series

Patch

diff --git a/os-posix.c b/os-posix.c
index a4284e2c07..5766346521 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -270,7 +270,7 @@  void os_setup_limits(void)
         return;
     }
 
-    nofile.rlim_cur = nofile.rlim_max;
+    nofile.rlim_cur = OPEN_MAX < nofile.rlim_max ? OPEN_MAX : nofile.rlim_max;
 
     if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
         warn_report("unable to set NOFILE limit: %s", strerror(errno));