From: Remi Tricot-Le Breton Date: Thu, 16 Dec 2021 16:14:34 +0000 (+0100) Subject: MINOR: vars: Move UPDATEONLY flag test to vars_set_ifexist X-Git-Tag: v2.6-dev1~287 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7055301934e3951270eac999b8f9168a81f81ed8;p=thirdparty%2Fhaproxy.git MINOR: vars: Move UPDATEONLY flag test to vars_set_ifexist 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. --- diff --git a/src/vars.c b/src/vars.c index f96bb27a96..4c5f88b896 100644 --- a/src/vars.c +++ b/src/vars.c @@ -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); }