From ba5b68be84888b24918dd019b87ed9f62d7fa988 Mon Sep 17 00:00:00 2001 From: Jiri Vymazal Date: Tue, 11 Feb 2020 13:46:23 +0100 Subject: [PATCH] Fixed processing of 'cofig.enabled' directive Previously the directive was processed way too late which caused false errors whenever it was set to 'off' and possibly other problems. --- grammar/rainerscript.c | 43+++++++++++++++++++++++---------------- grammar/rainerscript.h | 1 + runtime/rsconf.c | 10 +++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 8f14bbe319..4398e6011a 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -699,6 +699,22 @@ nvlstFindNameCStr(struct nvlst *lst, const char *const __restrict__ name) return lst; } +/* check if the nvlst is disabled, and mark config.enabled directive + * as used if it is not. Returns 1 if block is disabled, 0 otherwise. + */ +int nvlstChkDisabled(struct nvlst *lst) +{ + struct nvlst *valnode; + + if((valnode = nvlstFindNameCStr(lst, "config.enabled")) != NULL) { + lst->bUsed = 1; + if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) { + return 1; + } + } + return 0; +} + /* check if there are duplicate names inside a nvlst and emit * an error message, if so. @@ -1207,21 +1224,6 @@ nvlstGetParams(struct nvlst *lst, struct cnfparamblk *params, } } - /* now config-system parameters (currently a bit hackish, as we - * only have one...). -- rgerhards, 2018-01-24 - */ - if((valnode = nvlstFindNameCStr(lst, "config.enabled")) != NULL) { - if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) { - dbgprintf("config object disabled by configuration\n"); - /* flag all params as used to not emit error mssages */ - bInError = 1; - struct nvlst *val; - for(val = lst; val != NULL ; val = val->next) { - val->bUsed = 1; - } - } - } - /* done parameter processing */ if(bInError) { if(bValsWasNULL) @@ -4418,8 +4418,13 @@ cnfstmtNewAct(struct nvlst *lst) struct cnfstmt* cnfstmt; char namebuf[256]; rsRetVal localRet; - if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) + if((cnfstmt = cnfstmtNew(S_ACT)) == NULL) { goto done; + } + if (nvlstChkDisabled(lst)) { + dbgprintf("action disabled by configuration\n"); + cnfstmt->nodetype = S_NOP; + } localRet = actionNewInst(lst, &cnfstmt->d.act); if(localRet == RS_RET_OK_WARN) { parser_errmsg("warnings occured in file '%s' around line %d", @@ -5284,6 +5289,11 @@ includeProcessCnf(struct nvlst *const lst) goto done; } + if (nvlstChkDisabled(lst)) { + DBGPRINTF("include statement disabled\n"); + goto done; + } + pvals = nvlstGetParams(lst, &incpblk, NULL); if(pvals == NULL) { goto done; diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index bfa8ee6cb9..0f8128861b 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -340,6 +340,7 @@ void nvlstDestruct(struct nvlst *lst); void nvlstPrint(struct nvlst *lst); void nvlstChkUnused(struct nvlst *lst); struct nvlst* nvlstFindName(struct nvlst *lst, es_str_t *name); +int nvlstChkDisabled(struct nvlst *lst); struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst); void cnfobjDestruct(struct cnfobj *o); void cnfobjPrint(struct cnfobj *o); diff --git a/runtime/rsconf.c b/runtime/rsconf.c index fc0863a738..303e06365b 100644 --- a/runtime/rsconf.c +++ b/runtime/rsconf.c @@ -438,6 +438,16 @@ cnfDoObj(struct cnfobj *const o) dbgprintf("cnf:global:obj: "); cnfobjPrint(o); + + /* We need to check for object disabling as early as here to cover most + * of them at once and avoid needless initializations + * - jvymazal 2020-02-12 + */ + if (nvlstChkDisabled(o->nvlst)) { + dbgprintf("object disabled by configuration\n"); + return; + } + switch(o->objType) { case CNFOBJ_GLOBAL: glblProcessCnf(o);