Skip to content

Commit

Permalink
Fixed processing of 'cofig.enabled' directive
Browse files Browse the repository at this point in the history
Previously the directive was processed way too late which caused
false errors whenever it was set to 'off' and possibly other
problems.
  • Loading branch information
jvymazal committed Feb 12, 2020
1 parent 3858b85 commit ba5b68b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
46 changes: 28 additions & 18 deletions grammar/rainerscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,23 @@ 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) {
if(es_strbufcmp(valnode->val.d.estr, (unsigned char*) "on", 2)) {
return 1;
} else {
valnode->bUsed = 1;
}
}
return 0;
}


/* check if there are duplicate names inside a nvlst and emit
* an error message, if so.
Expand Down Expand Up @@ -1207,23 +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;
}
} else {
valnode->bUsed = 1;
}
}

/* done parameter processing */
if(bInError) {
if(bValsWasNULL)
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions grammar/rainerscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions runtime/rsconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ba5b68b

Please sign in to comment.