Raise RLIMIT_NPROC only if maxnprocs higher than current limits
All checks were successful
continuous-integration/drone/push Build is passing

Otherwise 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.

To mitigate this, we respect system defaults and only raise the limit if it is
an actual raise.
This commit is contained in:
Armin Friedl 2020-08-17 21:37:20 +02:00
parent 0144e4c783
commit d38603dc0e

23
main.c
View file

@ -285,16 +285,21 @@ main(int argc, char *argv[])
} }
/* raise the process limit */ /* raise the process limit */
rlim.rlim_cur = rlim.rlim_max = maxnprocs; if (getrlimit(RLIMIT_NPROC, &rlim) < 0) {
if (setrlimit(RLIMIT_NPROC, &rlim) < 0) { die("getrlimit RLIMIT_NPROC:");
die("setrlimit RLIMIT_NPROC:"); }
}
/* validate user and group */ rlim.rlim_cur = MAX(rlim.rlim_cur, maxnprocs);
errno = 0; rlim.rlim_max = MAX(rlim.rlim_max, maxnprocs);
if (!user || !(pwd = getpwnam(user))) { if (setrlimit(RLIMIT_NPROC, &rlim) < 0) {
die("getpwnam '%s': %s", user ? user : "null", die("setrlimit RLIMIT_NPROC:");
errno ? strerror(errno) : "Entry not found"); }
/* 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; errno = 0;
if (!group || !(grp = getgrnam(group))) { if (!group || !(grp = getgrnam(group))) {