Skip to contentSkip to conversation

os-posix: Expand setrlimit() syscall compatibility

PATCH Applied Trent Huber 5 participants 6 messages Jun 14, 2024 – Jun 17, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 os-posix: Expand setrlimit() syscall compatibility

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.

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

 os-posix.c | 4 ++++
 1 file changed, 4 insertions(+)
os-posix.c +4 -0
index a4284e2c07..43f9a43f3f 100644
@@ -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));
Signature · 1 line
2.24.3 (Apple Git-128)
Tested-by on v2 1/1
#1 lore raw

Hi Trent,

Quoted 19 lines · Trent Huber

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.

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

  os-posix.c | 4 ++++
  1 file changed, 4 insertions(+)
os-posix.c +0 -0
index a4284e2c07..43f9a43f3f 100644

os-posix.c void os_setup_limits(void) · line 274

Quoted 5 lines
os-posix.c +2 -0
@@ -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;

Why open-code min()? (The man-page also suggests it).

Quoted 6 lines
os-posix.c +2 -0
+#else
      nofile.rlim_cur = nofile.rlim_max;
+#endif
 
      if (setrlimit(RLIMIT_NOFILE, &nofile) < 0) {
          warn_report("unable to set NOFILE limit: %s", strerror(errno));
#2 lore raw
Quoted 17 lines · Philippe Mathieu-Daudé

Hi Trent,

Quoted 14 lines · Trent Huber

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.

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

  os-posix.c | 4 ++++

  1 file changed, 4 insertions(+)
Quoted 11 lines

os-posix.c void os_setup_limits(void) · line 273

Quoted 9 lines
os-posix.c +2 -0
index a4284e2c07..43f9a43f3f 100644
@@ -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;

Why open-code min()? (The man-page also suggests it).

I guess it's because stddef.h isn't included there, so min() isn't immediately available :)

Applied to trivial-patches,

/mjt

Signature · 4 lines
GPG Key transition (from rsa2048 to rsa4096) since 2024-04-24.
New key: rsa4096/61AD3D98ECDF2C8E  9D8B E14E 3F2A 9DD7 9199  28F1 61AD 3D98 ECDF 2C8E
Old key: rsa2048/457CE0A0804465C5  6EE1 95D1 886E 8FFB 810D  4324 457C E0A0 8044 65C5
Transition statement: http://www.corpit.ru/mjt/gpg-transition-2024.txt
#3 lore raw
Quoted 31 lines · Michael Tokarev
Quoted 17 lines · Philippe Mathieu-Daudé

Hi Trent,

Quoted 14 lines · Trent Huber

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.

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

  os-posix.c | 4 ++++

  1 file changed, 4 insertions(+)
Quoted 12 lines

os-posix.c void os_setup_limits(void) · line 274

Quoted 10 lines
os-posix.c +2 -0
index a4284e2c07..43f9a43f3f 100644
@@ -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;

Why open-code min()? (The man-page also suggests it).

Quoted 2 lines

I guess it's because stddef.h isn't included there, so min() isn't immediately available :)

I see os-posix.c -> "qemu/osdep.h" -> <stddef.h>. Anyway,

Quoted 1 line

Applied to trivial-patches,

Thanks!

#4 lore raw
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Michael Tokarev
Quoted 28 lines · Philippe Mathieu-Daudé

Hi Trent,

Quoted 19 lines · Trent Huber

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.

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

  os-posix.c | 4 ++++

  1 file changed, 4 insertions(+)
os-posix.c +0 -0
index a4284e2c07..43f9a43f3f 100644

os-posix.c void os_setup_limits(void) · line 273

Quoted 4 lines
os-posix.c +2 -0
@@ -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;

Why open-code min()? (The man-page also suggests it).

Quoted 4 lines
Quoted 2 lines

I guess it's because stddef.h isn't included there, so min() isn't immediately available :)

I see os-posix.c -> "qemu/osdep.h" -> <stddef.h>. Anyway,

We also have MIN in osdep.h.

r~

Reviewed-by on v2 1/1
#5 lore raw
In reply to Trent Huber
Quoted 5 lines · Trent Huber

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.

Quoted 8 lines

---
The previous version assumed OPEN_MAX was a constant defined on all POSIX systems--turns out it's only a macOS constant. This version adds preprocessing conditionals to maintain compatibility with Linux.

 os-posix.c | 4 ++++
 1 file changed, 4 insertions(+)>

With regards,
Daniel

Signature · 3 lines
|: 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 :|