147 Commits

Author SHA1 Message Date
Rainer Gerhards
a48cce29c9 conf optimizer: remove left-over NOPs
First step in optimizer is to replace unneded statements by NOP,
which are now removed in step 2.

closes see also https://github.com/rsyslog/rsyslog/issues/2432
2018-01-27 18:03:01 +01:00
Rainer Gerhards
6327e43ea9 config: add include() script object
This permits to include files (like legacy $IncludeConfig) via a
script object. Needless to say, the script object offers more
features:

- include files can now be
  - required, with rsyslog aborting when not present
  - required, with rsyslog emitting an error message but otherwise
    continuing when not present
  - optional, which means non-present include files will be
    skipped without notice
  This is controlled by the "mode" parameter.
- text can be included form e.g. an environment variable
  --> ex: include(text=`echo $ENVVAR`)

This finally really obsoletes $IncludeConfig.

closes https://github.com/rsyslog/rsyslog/issues/2151
2018-01-22 18:36:03 +01:00
Jan Gerhards
764deee8b3 ruleset: use new errmsg interface
see also https://github.com/rsyslog/rsyslog/issues/1684
2018-01-19 11:44:46 +01:00
PascalWithopf
29c9fb1f9a codestyle: reduce line length to 120
lines are still checked for a length of 125 because
these are just some of the lines
2017-12-21 17:09:32 +01:00
Rainer Gerhards
b63d3051bc RainerScript: add function script_error() and error-reporting support
This permits script functions that could fail to report errors back, so
that the user can handle them if desired. We use an errno-style of
interface. That means script_error() needs to be called after functions
that supports it. It will return either 0 (all OK) or something else
(an error condition).

The commit also modifies the parse_time() function to use the new
interface. First of all, this is useful for users, and secondly we
needed a capability to craft a testbench test.

closes https://github.com/rsyslog/rsyslog/issues/1978
2017-12-09 16:08:36 +01:00
Rainer Gerhards
1f109c53ca lookup: improve code in regard to err detection at compile time
Trying to understand CID 185407, which looks like a false positive. On
the way to this, add attributation which could increase correctness of
compiler code unerstanding and trigger different set of error messages.
2017-11-14 14:27:05 +01:00
Rainer Gerhards
b0d9c79b89 ruleset: "fix" coverity scan issue
while the issue is valid, this was not a bug but rather a
safeguard. Doing it slightly differntly this time.

CID 185393
2017-11-03 19:19:10 +01:00
Rainer Gerhards
3fbd901b3e core bugfix: potential segfault when shutting down rsyslog
when rulesets are nested a segfault can occur when shutting down
rsyslog. the reason is that rule sets are destructed in load order,
which means a "later" ruleset may still be active when an "earlier"
one was already destructed. In these cases, a "call" can invalidly
call into the earlier ruleset, which is destructed and so leads to
invalid memory access. If a segfault actually happens depends on the
OS, but it is highly probable.

The cure is to split the queue shutdown sequence. In a first step,
all worker threads are terminated and the queue set to enqOnly.
While some are terminated, it is still possible that the others
enqueue messages into the queue (which are then just placed into the
queue, not processed). After this happens, a call can no longer
be issued (as there are no more workers). So then we can destruct
the rulesets in any order.

closes https://github.com/rsyslog/rsyslog/issues/1122
2017-10-18 11:00:24 +02:00
Rainer Gerhards
3e3a487a12 bugfix core: lookup table reload was not properly integrated
The opcode was not handled, what lead to misleading messages
in debug log. Since we run debug builds more strictly, it also
causes an assertion to trigger, thus aborting the test.
2016-12-11 17:49:03 +01:00
Rainer Gerhards
d8d7fc58cd rainerscript: implement new "call_indirect" statement
closes https://github.com/rsyslog/rsyslog/issues/1318
2016-12-11 12:06:28 +01:00
purnima
d45daa2af0 Rebase,redefine msgDestruct() as smsg_t is used 2016-11-22 14:24:25 +05:30
Rainer Gerhards
448f16495c remove "inline" attribute from excessivly long functions 2016-10-26 11:50:15 +02:00
Rainer Gerhards
8a986092c6 fix old-style definitions (missing prototype in func def) 2016-06-03 10:08:57 +02:00
Rainer Gerhards
5e3b075d53 fix compiler warnings 2016-06-02 12:08:55 +02:00
Rainer Gerhards
634da58dbe stop using fjson_object_object_foreachC()
...and friends. This uses internals of the json library. It was
required when we used json-c, where distros often shipped versions
that did miss its clean counterpart. Now that we require
libfastjson, we can (and should) use the clean method.

closes https://github.com/rsyslog/rsyslog/issues/941
2016-04-07 17:54:32 +02:00
Janmejay Singh
b4e09c8570 fixing a false uninitialized-variable issue that clang static-analysis identifies as a problem 2016-03-31 22:55:03 +05:30
Janmejay Singh
d142b03985 fixed some problems identified by static-analysis on travis 2016-03-31 22:23:17 +05:30
Janmejay Singh
40fee60020 support for foreach loop over object 2016-03-31 20:03:45 +05:30
Peter Portante
d59bae3b06 Silence unknown statement errors in debug logs
When running with debugging enabled, we'll often see the following
error:

    error: unknown stmt type %u during iterateAll

Where "%u" is 4006 or 4007. This patch silences those errors by
adding them to the "ignore" case.
2016-03-24 04:04:59 +00:00
Janmejay Singh
25cc42c2ff pre-merged upstream for a clean merge-back 2016-02-04 16:14:21 +05:30
Rainer Gerhards
b435f4e7d2 bugfix: queue engine can loose one message during queue shutdown
... due to improper checking of return states.

closes https://github.com/rsyslog/rsyslog/issues/262
2016-02-03 16:42:50 +01:00
Janmejay Singh
79d1bdbc03 reload_lookup_table second-param(stub-value to be used in case of reload failure) made optional 2015-12-22 01:10:36 +05:30
Janmejay Singh
bf43179381 moved to async(dispatched on a different thread) lookup-table reload (stub param is still mandatory, making it optional requires more work) 2015-12-21 23:42:11 +05:30
Janmejay Singh
0f9bffc2f1 rscript based control for reload and stubbing of lookup-table 2015-12-18 20:04:16 +05:30
Janmejay Singh
a7f2b15352 copy json when reading-it from global variable, else ref-count it on its way out, so code that uses it can invoke freeing routine without worrying about it being global variable or not 2015-05-26 12:18:29 +05:30
Janmejay Singh
c9d7d85d01 Test and fix for "No initialization of action/call statements in body of foreach statement"
(+ added some files which were missed in the commit before, test related to asserting behavior when non-array object is iterated upon)
2015-04-14 08:54:54 +05:30
Janmejay Singh
b353879610 type-check object to ensure its an array before using it like one for loop 2015-04-08 12:35:35 +05:30
Rainer Gerhards
fac850f58c fix a couple of compiler warnings 2015-03-17 12:36:16 +01:00
Janmejay Singh
4ca5e217e2 Adds support for 'reset' statement (it has syntax similar to set 'set', but _unlike_ 'set' always force-sets the given value insteed of conditionally merging it, or not saving it because it is trying to replace an object with a leaf value etc).
Syntax:

reset $.foo = $!bar;

etc.
2014-12-17 11:39:31 +01:00
Janmejay Singh
66d459daa9 foreach for rscript + test (completes json-array support, except documentation) 2014-12-17 11:39:30 +01:00
Rainer Gerhards
cca1519b58 Merge branch 'v7-stable' into v8-stable 2014-10-29 18:01:11 +01:00
Rainer Gerhards
1f4754cdcf undo commit 3996fe6acaf8da6eab1aed2fa561098e370496ab - was no good idea
We need to handle this differently, will break too many existing
configurations.
2014-10-29 17:59:56 +01:00
Rainer Gerhards
1be4d911e9 Merge branch 'v7-stable' into v8-stable 2014-10-27 15:42:53 +01:00
Rainer Gerhards
3996fe6aca warn on invalid ruleset name
but keep accepting it. This is a forward-compatibility change
so that users will not run into surprises when they apply 8.5.1.
2014-10-27 15:42:08 +01:00
Rainer Gerhards
4b1964712c Merge branch 'v7-stable' into v8-stable
Conflicts:
	runtime/ruleset.c
2014-07-22 22:52:29 +02:00
Rainer Gerhards
a811e3386c fix regression (mem leak during normal operations) from commit b7a34ab022b4f427d0a73fc6ac37230e1ca29a84 2014-07-22 22:45:44 +02:00
Tomas Heinrich
19aa27d3aa bugfix: plug a memleak in rulesetProcessCnf()
Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/runtime/ruleset.c:984: alloc_arg: "rulesetConstruct(ruleset_t **)" allocates memory that is stored into "pRuleset".
rsyslog-7.4.10/runtime/ruleset.c:729:1: alloc_fn: Storage is returned from allocation function "calloc(size_t, size_t)".
rsyslog-7.4.10/runtime/ruleset.c:729:1: var_assign: Assigning: "pThis" = "calloc(1UL, 56UL)".
rsyslog-7.4.10/runtime/ruleset.c:729:1: noescape: Resource "pThis" is not freed or pointed-to in function "rulesetInitialize(ruleset_t *)".
rsyslog-7.4.10/runtime/ruleset.c:726:1: noescape: "rulesetInitialize(ruleset_t *)" does not free or save its pointer parameter "pThis".
rsyslog-7.4.10/runtime/ruleset.c:729:1: var_assign: Assigning: "*ppThis" = "pThis".
rsyslog-7.4.10/runtime/ruleset.c:985: noescape: Resource "pRuleset" is not freed or pointed-to in function "rulesetSetName(ruleset_t *, uchar *)".
rsyslog-7.4.10/runtime/ruleset.c:638:43: noescape: "rulesetSetName(ruleset_t *, uchar *)" does not free or save its pointer parameter "pThis".
rsyslog-7.4.10/runtime/ruleset.c:1011: leaked_storage: Variable "pRuleset" going out of scope leaks the storage it points to.
2014-07-22 18:30:01 +02:00
Tomas Heinrich
b46d1765ef bugfix: don't leak memory returned by newActive()
Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/runtime/ruleset.c:506: alloc_fn: Storage is returned from allocation function "newActive(batch_t *)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: return_alloc_fn: Directly returning storage allocated by "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:506: var_assign: Assigning: "thenAct" = storage returned from "newActive(pBatch)".
rsyslog-7.4.10/runtime/ruleset.c:509: leaked_storage: Variable "thenAct" going out of scope leaks the storage it points to.
2014-07-22 17:57:25 +02:00
Tomas Heinrich
029cf3e1b4 bugfix: don't leak memory returned by newActive()
Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/runtime/ruleset.c:326: alloc_fn: Storage is returned from allocation function "newActive(batch_t *)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: return_alloc_fn: Directly returning storage allocated by "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:326: var_assign: Assigning: "newAct" = storage returned from "newActive(pBatch)".
rsyslog-7.4.10/runtime/ruleset.c:362: leaked_storage: Variable "newAct" going out of scope leaks the storage it points to.

Error: RESOURCE_LEAK (CWE-772):
rsyslog-7.4.10/runtime/ruleset.c:373: alloc_fn: Storage is returned from allocation function "newActive(batch_t *)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: alloc_fn: Storage is returned from allocation function "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:220:2: return_alloc_fn: Directly returning storage allocated by "malloc(size_t)".
rsyslog-7.4.10/runtime/ruleset.c:373: var_assign: Assigning: "newAct" = storage returned from "newActive(pBatch)".
rsyslog-7.4.10/runtime/ruleset.c:376: leaked_storage: Variable "newAct" going out of scope leaks the storage it points to.
2014-07-22 17:57:08 +02:00
Tomas Heinrich
e0d7c95cd7 don't allocate a 0B chunk of memory
Error: CLANG_WARNING:
rsyslog-7.4.10/runtime/ruleset.c:220:9: warning: Call to 'malloc' has an allocation size of 0 bytes
2014-07-22 17:52:00 +02:00
Rainer Gerhards
5cba7d2f55 Merge branch 'v7-stable' into v8-stable 2014-07-09 11:56:44 +02:00
Rainer Gerhards
84f984f5b5 bugfix: double-free when ruleset() parser parameters were used
While unlikely, this could cause stability issues even after the
config phase.
2014-07-09 11:56:18 +02:00
John Novotny
f52fa0c1cd bugfix: do not execut discarded messages with async call 2014-03-12 15:32:23 +01:00
John Novotny
88af2e7f26 bugfix: async ruleset did process already-deleted messages 2014-03-12 12:46:35 +01:00
Rainer Gerhards
c5ebb91826 bugfix: STOP/discard(~) was mostly NOT honored
This lead to execution of config code that was not meant to be executed.
2013-11-18 17:24:33 +01:00
Rainer Gerhards
2387c9281d fix: ruleset queues were activated too early
This does not cause issues in v7, but here we have the problem
that the total number of actions, which now is required for wti sizing,
is not available at that early stage. So we needed to delay queue
startup until everything is processed (just as it should have been
already!). Note the previously we could have a segfault on first message
when ruleset queues were used.
2013-11-14 15:51:52 +01:00
Rainer Gerhards
2a94703425 refactor action disabling 2013-11-06 12:24:49 +01:00
Rainer Gerhards
176dea7654 make batches of 1 commit automatically after each action
This improves failover handling and makes it consistent with doc
(precise handling for batches of one).
2013-11-06 11:28:44 +01:00
Rainer Gerhards
268bd872ed simplify submitToActionQ...() code path 2013-11-05 16:04:27 +01:00
Rainer Gerhards
c4f14fa28c Merge branch 'master-ruleeng' into master-ruleeng-simd
Conflicts:
	runtime/ruleset.c

required refactoring of (asnyc) call code
2013-11-05 11:49:32 +01:00