]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: limits: add is_any_limit_configured
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Wed, 10 Jul 2024 12:18:12 +0000 (14:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 10 Jul 2024 16:05:48 +0000 (18:05 +0200)
Let's encapsulate the check of all supported for now process internal limits in
a separate function. This will help in cases, when we need to simply check if
we have even only one limit set in the configuration file. It's important, as
the default value for a one limit (fd-hard-limits, for example) sometimes must
not affect the computation of the others.

src/limits.c

index 60c07d2061d439068389c212e4c55a203ba8070d..c5b4820c64f6b5686c57e63cd5477f18d5435c11 100644 (file)
@@ -41,6 +41,21 @@ int raise_rlim_nofile(struct rlimit *old_limit, struct rlimit *new_limit)
        return ret;
 }
 
+/* Encapsulates the check of all supported for now process internal limits,
+ * which could be provided via config or/and cmdline. Returns 1, if even only
+ * one supported limit is set, otherwise 0.
+ */
+static int is_any_limit_configured()
+{
+       int ret = 0;
+
+       if (global.maxconn || global.rlimit_nofile || global.rlimit_memmax ||
+               global.fd_hard_limit)
+               ret = 1;
+
+       return ret;
+}
+
 /* considers splicing proxies' maxconn, computes the ideal global.maxpipes
  * setting, and returns it. It may return -1 meaning "unlimited" if some
  * unlimited proxies have been found and the global.maxconn value is not yet
@@ -134,8 +149,7 @@ int compute_ideal_maxconn()
         * if only one of these ha-specific limits is presented in config or in
         * the cmdline.
         */
-       if (!global.fd_hard_limit && !global.maxconn && !global.rlimit_nofile
-           && !global.rlimit_memmax)
+       if (!is_any_limit_configured())
                global.fd_hard_limit = DEFAULT_MAXFD;
 
        if (remain > global.fd_hard_limit)