]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: vars: Move UPDATEONLY flag test to vars_set_ifexist
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Thu, 16 Dec 2021 16:14:34 +0000 (17:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 16 Dec 2021 16:31:27 +0000 (17:31 +0100)
The vars_set_by_name_ifexist function was created to avoid creating too
many variables from a LUA module. This was made thanks to the
VF_UPDATEONLY flags which prevented variable creation in the var_set
function. Since commit 3a4bedccc ("MEDIUM: vars: replace the global name
index with a hash") this limitation was restricted to 'proc' scope
variables only.
This patch simply moves the scope test to the vars_set_by_name_ifexist
function instead of the var_set function.

src/vars.c

index f96bb27a96c11b5d0bf119bb650711d6870e6212..4c5f88b896e16da09ec6b085545b7faf04fa312e 100644 (file)
@@ -310,8 +310,7 @@ static int smp_fetch_var(const struct arg *args, struct sample *smp, const char
  * a bool (which is memory-less).
  *
  * Flags is a bitfield that may contain one of the following flags:
- *   - VF_UPDATEONLY: if the scope is SCOPE_PROC, the variable may only be
- *     updated but not created.
+ *   - VF_UPDATEONLY: the variable may only be updated but not created.
  *   - VF_CREATEONLY: do nothing if the variable already exists (success).
  *   - VF_PERMANENT: this flag will be passed to the variable upon creation
  *
@@ -351,8 +350,7 @@ static int var_set(uint64_t name_hash, enum vars_scope scope, struct sample *smp
                                            -var->data.u.meth.str.data);
                }
        } else {
-               /* creation permitted for proc ? */
-               if (flags & VF_UPDATEONLY && scope == SCOPE_PROC)
+               if (flags & VF_UPDATEONLY)
                        goto unlock;
 
                /* Check memory available. */
@@ -502,7 +500,8 @@ int vars_check_arg(struct arg *arg, char **err)
        return 1;
 }
 
-/* This function stores a sample in a variable if it was already defined.
+/* This function stores a sample in a variable unless it is of type "proc" and
+ * not defined yet.
  * Returns zero on failure and non-zero otherwise. The variable not being
  * defined is treated as a failure.
  */
@@ -515,7 +514,8 @@ int vars_set_by_name_ifexist(const char *name, size_t len, struct sample *smp)
        if (!vars_hash_name(name, len, &scope, &hash, NULL))
                return 0;
 
-       return var_set(hash, scope, smp, VF_UPDATEONLY);
+       /* Variable creation is allowed for all scopes apart from the PROC one. */
+       return var_set(hash, scope, smp, (scope == SCOPE_PROC) ? VF_UPDATEONLY : 0);
 }