Currently maxnprocs may actually lower the limit. Especially when using the
default limit of 512, this quickly causes quark's fork() to fail when started
with a non-exclusive user which may easily have a couple hundred process 
running before even starting quark.

To mitigate this, we respect system defaults and only raise the limit if it is
an actual raise. At least in the default case this makes sense in my opinion.
If an explicit `-n` argument is given it may make sense to also actually lower 
the limit.

---
 main.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/main.c b/main.c
index 0542fab..0c43584 100644
--- a/main.c
+++ b/main.c
@@ -285,16 +285,21 @@ main(int argc, char *argv[])
        }
 
        /* raise the process limit */
-       rlim.rlim_cur = rlim.rlim_max = maxnprocs;
-       if (setrlimit(RLIMIT_NPROC, &rlim) < 0) {
-               die("setrlimit RLIMIT_NPROC:");
-       }
-
-       /* validate user and group */
-       errno = 0;
-       if (!user || !(pwd = getpwnam(user))) {
-               die("getpwnam '%s': %s", user ? user : "null",
-                   errno ? strerror(errno) : "Entry not found");
+  if (getrlimit(RLIMIT_NPROC, &rlim) < 0) {
+    die("getrlimit RLIMIT_NPROC:");
+  }
+
+  rlim.rlim_cur = MAX(rlim.rlim_cur, maxnprocs);
+  rlim.rlim_max = MAX(rlim.rlim_max, maxnprocs);
+  if (setrlimit(RLIMIT_NPROC, &rlim) < 0) {
+    die("setrlimit RLIMIT_NPROC:");
+  }
+
+  /* validate user and group */
+  errno = 0;
+  if (!user || !(pwd = getpwnam(user))) {
+    die("getpwnam '%s': %s", user ? user : "null",
+        errno ? strerror(errno) : "Entry not found");
        }
        errno = 0;
        if (!group || !(grp = getgrnam(group))) {
-- 
2.26.2


Reply via email to