]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
main: when generating the resource limit to pass to children, take FD_SETSIZE into...
authorLennart Poettering <lennart@poettering.net>
Wed, 16 Jan 2019 17:06:18 +0000 (18:06 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Jan 2019 16:31:36 +0000 (17:31 +0100)
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.

src/core/main.c

index 1b81542e8c8765dae9467dd6e7cfab7eb0cd62d7..561f956f0a5b9edbe8287dc723833e6f4413a3a5 100644 (file)
@@ -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;
         }