From: Lennart Poettering Date: Wed, 16 Jan 2019 17:06:18 +0000 (+0100) Subject: main: when generating the resource limit to pass to children, take FD_SETSIZE into... X-Git-Tag: v241-rc1~23^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99a2fd3bcaa123d38a2d757cb3693e31e138e56b;p=thirdparty%2Fsystemd.git main: when generating the resource limit to pass to children, take FD_SETSIZE into consideration When we synthesize a "struct rlimit" structure to pass on for RLIMIT_NOFILE to our children, let's explicitly make sure that the soft limit is not above FD_SETSIZE, for compat reason with select(). Note this only applies when we derive the "struct rlimit" from what we inherited. If the user configures something explicitly it always takes precedence. --- diff --git a/src/core/main.c b/src/core/main.c index 1b81542e8c8..561f956f0a5 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1304,6 +1304,11 @@ static int bump_rlimit_nofile(struct rlimit *saved_rlimit) { if (arg_system) rl->rlim_max = MIN((rlim_t) nr, MAX(rl->rlim_max, (rlim_t) HIGH_RLIMIT_NOFILE)); + /* If for some reason we were invoked with a soft limit above 1024 (which should never + * happen!, but who knows what we get passed in from pam_limit when invoked as --user + * instance), then lower what we pass on to not confuse our children */ + rl->rlim_cur = MIN(rl->rlim_cur, (rlim_t) FD_SETSIZE); + arg_default_rlimit[RLIMIT_NOFILE] = rl; }