affile: Restore fsync & flush-lines functionality

Back in May, in 101cb379, which moved fsync() from logtransport to
logproto, a new argument for log_proto_file_writer_new() was
introduced, but when updating the call sites, the flush_lines and
fsync arguments were mixed up.

This corrects that, restoring both flush-lines() and fsync()
functionality for the file destination.

Reported-by: Evan Rempel <erempel@uvic.ca>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
logrewrite: fix rewrite set/subst related segfault

If a set/rewrite operation is referenced from multiple locations, and
it uses template functions, a segfault has occurred, as the clone
operation didn't properly propagate the associated configuration object,
which rendered template->cfg to be NULL, which in turn caused
template-function lookup code to dereference a NULL pointer.

This was fixed by two dependent changes:
  - always passing the already-compiled LogTemplate to the rewrite
    operations instead of a string constant.
  - reusing the compiled template object in clone()

Since LogTemplate is reused, and the first one contains a proper reference
to the appropriate configuration object, the NULL deref issue was
solved too.

Reported-By: Johnson, Chris <chris.johnson3@hp.com>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logrewrite: Fix the template reference counting

In case of the subst() and set() rewrite statements, when the
implementation was changed to pass a template to the constructor
instead of a string, the free() remained in the parser. While that was
supposed to free a string allocated by the parser, after the change,
that free'd the template that we had stored in the rewrite struct
itself.

To correct the issue, both the subst() and set() constructors will ref
the template, and the parser-side will unref it, instead of free()ing
it up.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Preparations for 3.4.1.

NEWS & VERSION updated for 3.4.1.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
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>
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>
cfg-tree: Fix empty block support

When compiling a sequence, only call
cfg_tree_propagate_expr_node_properties_to_pipe() when there's a pipe
to propagate properties to: when either of first_pipe or last_pipe
non-NULL. Otherwise, fall back to the case where we create an empty
pipe by hand.

This fixes a NULL dereference at config parsing time, when the config
had empty blocks.

Reported-by: Peter Czanik <czanik@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
patterndb: fixed a failed assertion when using builtin values in a pattern

An assertion was failed when using a db-parser() pattern that contains
a builtin name-value pair, like:

replace HOST with @ANYSTRING:HOST@

This is fixed by this patch.

Reported-By: Evan Rempel <erempel@uvic.ca>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
lib/control.c: An EOF on the control channel is not an error

An EOF on the control channel is not an error - that often happens
during normal procedures, when syslog-ng-ctl simply disconnects. So
lower the msg_error() to an msg_notice(), because that's what this
really is.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
persist-state: Set the persist state fd to close-on-exec

The persist state file's file descript should not be leaked through to
sub-processes, so set the close-on-exec flag on it when opening it.

Reported-by: Evan Rempel <erempel@uvic.ca>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
system-source: Make /proc/kmsg optional

In certain environments (vserver and OpenVZ come to mind), /proc/kmsg is
not readable, not even for root. On these systems, emit a warning, and
skip it, instead of aborting the startup.

Reported-by: Tamas Pal <folti@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
cfg-args: split off from cfg-lexer.c

This is a preparatory patch that slices off functionality from cfg-lexer.c
to make it easier to write unit tests for.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
cfg-lexer.h: added GError based error handling boilerplate

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