mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-11 03:31:36 +00:00
MINOR: config: add predicate "defined()" to conditional expression blocks
"defined(name)" will return true if <name> is a defined environment variable otherwise false, regardless of its contents.
This commit is contained in:
parent
732525fae7
commit
42ed14b529
@ -807,9 +807,20 @@ The conditions are currently limited to:
|
|||||||
- an empty string, always returns "false"
|
- an empty string, always returns "false"
|
||||||
- the integer zero ('0'), always returns "false"
|
- the integer zero ('0'), always returns "false"
|
||||||
- a non-nul integer (e.g. '1'), always returns "true".
|
- a non-nul integer (e.g. '1'), always returns "true".
|
||||||
|
- a predicate optionally followed by argument(s) in parenthesis.
|
||||||
|
|
||||||
Other patterns are not supported yet but the purpose is to bring a few
|
The list of currently supported predicates is the following:
|
||||||
functions to test for certain build options and supported features.
|
|
||||||
|
- defined(<name>) : returns true if an environment variable <name>
|
||||||
|
exists, regardless of its contents
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
.if defined(HAPROXY_MWORKER)
|
||||||
|
listen mwcli_px
|
||||||
|
bind :1111
|
||||||
|
...
|
||||||
|
.endif
|
||||||
|
|
||||||
Three other directives are provided to report some status:
|
Three other directives are provided to report some status:
|
||||||
|
|
||||||
|
@ -136,6 +136,7 @@ enum nested_cond_state {
|
|||||||
/* supported conditional predicates for .if/.elif */
|
/* supported conditional predicates for .if/.elif */
|
||||||
enum cond_predicate {
|
enum cond_predicate {
|
||||||
CFG_PRED_NONE, // none
|
CFG_PRED_NONE, // none
|
||||||
|
CFG_PRED_DEFINED, // "defined"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cond_pred_kw {
|
struct cond_pred_kw {
|
||||||
@ -146,6 +147,7 @@ struct cond_pred_kw {
|
|||||||
|
|
||||||
/* supported condition predicates */
|
/* supported condition predicates */
|
||||||
const struct cond_pred_kw cond_predicates[] = {
|
const struct cond_pred_kw cond_predicates[] = {
|
||||||
|
{ "defined", CFG_PRED_DEFINED, ARG1(1, STR) },
|
||||||
{ NULL, CFG_PRED_NONE, 0 }
|
{ NULL, CFG_PRED_NONE, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1712,6 +1714,10 @@ static int cfg_eval_condition(char **args, char **err, const char **errptr)
|
|||||||
* arguments, placed in <argp> (which we'll need to free).
|
* arguments, placed in <argp> (which we'll need to free).
|
||||||
*/
|
*/
|
||||||
switch (cond_pred->prd) {
|
switch (cond_pred->prd) {
|
||||||
|
case CFG_PRED_DEFINED: // checks if arg exists as an environment variable
|
||||||
|
ret = getenv(argp[0].data.str.area) != NULL;
|
||||||
|
goto done;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
memprintf(err, "internal error: unhandled conditional expression predicate '%s'", cond_pred->word);
|
memprintf(err, "internal error: unhandled conditional expression predicate '%s'", cond_pred->word);
|
||||||
if (errptr)
|
if (errptr)
|
||||||
|
Loading…
Reference in New Issue
Block a user