loggen: Bail out if no path is specified when using unix sockets

When using loggen -x, the path is mandatory, so bail out if none were
specified, instead of crashing with a segmentation fault.

Reported-by: Peter Czanik <czanik@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
filter: fixed "modify" property for FilterCall instances

The modify property for FilterCall instances were not properly propagated
to callers.

This patch also changes that "modify" is calculated during the init method
rather than doing it in the constructor.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
filter: add filter invocation functions that automatically make the LogMessage writable

In case a filter is not read-only, we have to make sure that our LogMessage
instance is writable. Introduce a new set of function that does
exactly that.

The old ones still exist as in some cases filter invocation is not
on a log processing path (patterndb actions, etc), in which case we
still have to be able to invoke them.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
filter: use filter_expr_eval_root() instead of calling log_msg_make_writable()

Use the new filter_expr_eval_root() function.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogRewrite: use filter_expr_eval_root() for condition()

This actually fixes a failed assertion, which happens when the filter
expression writes to the LogMessage, as earlier the message may
be read-only by the time it gets here.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
VERSION: bump version number to 3.5.0alpha0
scratch-buffers: Support any number of stacks

Instead of being tied to GStrings only, support registering new kinds
of stacks, which will be automatiaclly free'd on thread shutdown. For
convenience, wrappers are provided for GString-based scratch buffer
acquire and release, and that stack is automatically registered and
free'd by the library itself.

This fixes #2.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
systemd: Add a Restart=on-failure option to the service file

In case syslog-ng goes down due to an unexpected signal, or perhaps a
crash, we want logging to resume, so tell systemd to restart the
service on failure.

Reported-by: Paul Dann <pdgiddie+balabit@gmail.com>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
LogPipe: define macro to encompass all branch related flags

To make it easier to use all branch properties assigned to a LogPipe,
define PIF_BRANCH_PROPERTIES the sum of all such flags.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogMultiplexer: propagate branch properties to the head of the branch

Since the compilation process doesn't always have all the context to
propagate branch-related LogPipe flags back to the head element
of the LogMultiplexer branches, do that in log_multiplexer_init().

We basically pick up "final" and "fallback" flags from Pipes on a branch
regardless if they have been set on the branch head or on subsequent
elements.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-tree: make sure final/fallback flags are applied to at least one LogPipe on a branch

In some cases (when a branch contains a source reference), the
fallback/final flags could've been missed, causing syslog-ng to ignore
them even if specified in the configuration file.

This patch together with its parent puts these flags to at least one
LogPipe instance on a branch, which is then picked by LogMultiplexer
in its init() method.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
persist-state: added an assertion to check if mapped_counter is managed properly

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoBufferedServer: refactor to make functions smaller

This patch refactors LogProtoBufferedServer a bit to make it easier to
implement multi-line input formats. Among others:

  * it renames fetch_from_buf method to fetch_from_buffer
  * the reading of the input stream is split off to a separate
    fetch_into_buffer() method
  * it gets rid off "flush_the_rest" parameter, a separate function
    is introduced named is_input_closed() that allows the caller to determine
    if there's a chance to read further data into the input stream.
  * a new method named clear_buffer() is introduced that resets the buffer
    to contain nothing.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoBufferedServerState: deprecate buffer_cached_eol member

There are multiple reasons it was a bad idea to stored buffer_cached_eol
in the state structure:
  - the buffer_cached_eol member belongs to LogProtoTextServer in the first
    place
  - the cached_eol is just a cache, it could have been recalculated
    anyway when the state is reloaded, the least concern we have at restart
    time is that we need to relocate the closing EOL mark in our buffer
  - for multi-line support more state would be required.

Since this affects the persist file format the patch needs to work with
old persist files properly. For that reason the member is not completely
removed, but a dummy entry remains. We always set that member to 0, whenever
we load or upgrade a persist entry.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
lib/logproto: move all LogProto files under a subdirectory

Creating a subdirectory to hold all LogProto related files makes things
a bit easier to navigate, especially as I plan to move unit tests
under the respective directories to make them easier to run.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logproto: move unit tests to lib/logproto
test_findeom: fixes compilation warnings about pointer signedness
test_logproto: added testcase to cover the case of actually having an EOL before an EOF
proto_lib.h: introduce PROTO_TESTCASE macro

Instead of calling log_proto_testcase_begin() manually, introduce a macro
that does some housekeeping and removes some cruft from individual
testcases.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
test_logproto: factor out LogProtoServerOptions related testcases to a separate module

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>