]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: compression: move the default setting of maxzlibmem to defaults
authorWilly Tarreau <w@1wt.eu>
Mon, 25 Apr 2022 17:29:10 +0000 (19:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Apr 2022 17:42:43 +0000 (19:42 +0200)
__comp_fetch_init() only presets the maxzlibmem, and only when both
USE_ZLIB and DEFAULT_MAXZLIBMEM are set. The intent is to preset a
default value to protect the system against excessive memory usage
when no setting is set by the user.

Nowadays the entry in the global struct is always there so there's no
point anymore in passing via a constructor to possibly set this value.
Let's go the cleaner way by always presetting DEFAULT_MAXZLIBMEM to 0
in defaults.h unless these conditions are met, and always assigning it
instead of pre-setting the entry to zero. This is more straightforward
and removes some ifdefs and the last constructor. In addition, now the
setting has a chance of being found.

include/haproxy/defaults.h
src/compression.c
src/haproxy.c

index d4721a7948f890c6026474c7c5784499b2b958d2..80b2e643137843c4f39d5fdaefa0e55f62b29e80 100644 (file)
 #define HAPROXY_MEMMAX 0
 #endif
 
+/* For USE_ZLIB, DEFAULT_MAXZLIBMEM may be set to a hard-coded value that will
+ * preset a maxzlibmem value. Just leave it to zero for other configurations.
+ * Note that it's expressed in megabytes.
+ */
+#if !defined(DEFAULT_MAXZLIBMEM) || !defined(USE_ZLIB)
+#undef DEFAULT_MAXZLIBMEM
+#define DEFAULT_MAXZLIBMEM 0
+#endif
+
 /* Pools are always enabled unless explicitly disabled. When disabled, the
  * calls are directly passed to the underlying OS functions.
  */
index 8095ecb99f7bd0906c334f799617cb74f6875b86..3ce2a60057f35430df6720da458e780607e41a3b 100644 (file)
@@ -713,14 +713,6 @@ static struct cfg_kw_list cfg_kws = {ILH, {
 
 INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
 
-__attribute__((constructor))
-static void __comp_fetch_init(void)
-{
-#if defined(USE_ZLIB) && defined(DEFAULT_MAXZLIBMEM)
-       global.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U;
-#endif
-}
-
 static void comp_register_build_opts(void)
 {
        char *ptr = NULL;
index ddb23e2c8e6d797b5c5aae24b95ae4526aa4374e..6fbe85bd3c084448cde184fb0ca06f894db78895 100644 (file)
@@ -175,7 +175,7 @@ struct global global = {
        .nbthread = 0,
        .req_count = 0,
        .logsrvs = LIST_HEAD_INIT(global.logsrvs),
-       .maxzlibmem = 0,
+       .maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U,
        .comp_rate_lim = 0,
        .ssl_server_verify = SSL_SERVER_VERIFY_REQUIRED,
        .unix_bind = {