diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-15 15:32:11 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2011-07-15 15:32:11 +0200 |
commit | 84ca2c443680de2c7e98f27972fb6300a025d62d (patch) | |
tree | c053b6cfbfc1655be8b4c62b9cc3143aebfa5169 | |
parent | e579791a78267353566c79c83043805a54d85b74 (diff) | |
download | rsyslog-84ca2c443680de2c7e98f27972fb6300a025d62d.tar.gz rsyslog-84ca2c443680de2c7e98f27972fb6300a025d62d.tar.xz rsyslog-84ca2c443680de2c7e98f27972fb6300a025d62d.zip |
better check for config errors
-rw-r--r-- | grammar/mini.samp | 4 | ||||
-rw-r--r-- | grammar/rainerscript.c | 44 | ||||
-rw-r--r-- | grammar/rainerscript.h | 35 | ||||
-rw-r--r-- | grammar/testdriver.c | 3 |
4 files changed, 63 insertions, 23 deletions
diff --git a/grammar/mini.samp b/grammar/mini.samp index 505ae67a..3bb0de44 100644 --- a/grammar/mini.samp +++ b/grammar/mini.samp @@ -1,5 +1,5 @@ #global (dnscache="yes" arg1="1 2" arg2 = "1 2" arg3 ="1=2\"3") -action(type="omuser" target="all") +action(type="omuser" target="all" target="all2") global (dnscache="no" b="2") $FileOwner root *.* * @@ -28,6 +28,6 @@ if not (1==0) and 2*4/-5--(10-3)>7/*pri("*.*")*/ then { action(type="omfile" taget="/var/log/log5") action(type="omfile" taget="/var/log/log6") action(type="omfwd" taget="10.0.0.1" port="514") - action(type="omwusr" taget="rger") + action(type="omwusr" taget="rger" taget="rger2") } if getenv("user") == "test" then /var/log/testlog diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c index 5d64abb4..16140a3f 100644 --- a/grammar/rainerscript.c +++ b/grammar/rainerscript.c @@ -95,7 +95,8 @@ nvlstNew(es_str_t *name, es_str_t *value) if((lst = malloc(sizeof(struct nvlst))) != NULL) { lst->next = NULL; lst->name = name; - lst->value = value; + lst->val.datatype = 'S'; + lst->val.d.estr = value; } return lst; @@ -110,7 +111,8 @@ nvlstDestruct(struct nvlst *lst) toDel = lst; lst = lst->next; es_deleteStr(toDel->name); - es_deleteStr(toDel->value); + if(toDel->val.datatype == 'S') + es_deleteStr(toDel->val.d.estr); free(toDel); } } @@ -122,7 +124,8 @@ nvlstPrint(struct nvlst *lst) dbgprintf("nvlst %p:\n", lst); while(lst != NULL) { name = es_str2cstr(lst->name, NULL); - value = es_str2cstr(lst->value, NULL); + // TODO: support for non-string types + value = es_str2cstr(lst->val.d.estr, NULL); dbgprintf("\tname: '%s', value '%s'\n", name, value); free(name); free(value); @@ -130,12 +133,47 @@ nvlstPrint(struct nvlst *lst) } } +/* find a name starting at node lst. Returns node with this + * name or NULL, if none found. + */ +struct nvlst* +nvlstFindName(struct nvlst *lst, es_str_t *name) +{ + while(lst != NULL && es_strcmp(lst->name, name)) + lst = lst->next; + return lst; +} + + +/* check if there are duplicate names inside a nvlst and emit + * an error message, if so. + */ +static inline void +nvlstChkDupes(struct nvlst *lst) +{ + char *cstr; + + while(lst != NULL) { + if(nvlstFindName(lst->next, lst->name) != NULL) { + cstr = es_str2cstr(lst->name, NULL); + parser_errmsg("duplicate parameter '%s' -- " + "interpretation is ambigious, one value " + "will be randomly selected. Fix this problem.", + cstr); + free(cstr); + } + lst = lst->next; + } +} + + struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst) { struct cnfobj *o; if((o = malloc(sizeof(struct nvlst))) != NULL) { + nvlstChkDupes(lst); o->objType = objType; o->nvlst = lst; } diff --git a/grammar/rainerscript.h b/grammar/rainerscript.h index 3129ed25..2c4d764f 100644 --- a/grammar/rainerscript.h +++ b/grammar/rainerscript.h @@ -40,6 +40,22 @@ cnfobjType2str(enum cnfobjType ot) enum cnfactType { CNFACT_V2, CNFACT_LEGACY }; +/* a variant type, for example used for expression evaluation + * 2011-07-15/rger: note that there exists a "legacy" object var_t, + * which implements the same idea, but in a suboptimal manner. I have + * stipped this down as much as possible, but will keep it for a while + * to avoid unnecessary complexity during development. TODO: in the long + * term, var_t shall be replaced by struct var. + */ +struct var { + union { + es_str_t *estr; + struct cnfexpr *expr; + long long n; + } d; + char datatype; /* 'N' number, 'S' string, 'E' expression */ +}; + struct cnfobj { enum cnfobjType objType; struct nvlst *nvlst; @@ -48,7 +64,7 @@ struct cnfobj { struct nvlst { struct nvlst *next; es_str_t *name; - es_str_t *value; + struct var val; }; struct cnfcfsyslinelst { @@ -156,27 +172,12 @@ struct x { }; */ -/* a variant type, for example used for expression evaluation - * 2011-07-15/rger: note that there exists a "legacy" object var_t, - * which implements the same idea, but in a suboptimal manner. I have - * stipped this down as much as possible, but will keep it for a while - * to avoid unnecessary complexity during development. TODO: in the long - * term, var_t shall be replaced by struct var. - */ -struct var { - union { - es_str_t *estr; - long long n; - } d; - char datatype; /* 'N' - number, 'S' - string */ -}; - - int cnfParseBuffer(char *buf, unsigned lenBuf); void readConfFile(FILE *fp, es_str_t **str); struct nvlst* nvlstNew(es_str_t *name, es_str_t *value); void nvlstDestruct(struct nvlst *lst); void nvlstPrint(struct nvlst *lst); +struct nvlst* nvlstFindName(struct nvlst *lst, es_str_t *name); struct cnfobj* cnfobjNew(enum cnfobjType objType, struct nvlst *lst); void cnfobjDestruct(struct cnfobj *o); void cnfobjPrint(struct cnfobj *o); diff --git a/grammar/testdriver.c b/grammar/testdriver.c index 784e286e..b29626d4 100644 --- a/grammar/testdriver.c +++ b/grammar/testdriver.c @@ -88,7 +88,8 @@ void cnfDoBSDHost(char *ln) } es_str_t* -cnfGetVar(char *name, void *usrptr) +cnfGetVar(char __attribute__((unused)) *name, + void __attribute__((unused)) *usrptr) { es_str_t *estr; estr = es_newStrFromCStr("", 1); |