test_nvtable: make functions static

So that we can notice if a test function is not being called as the compiler
will warn about it. And its good style anyway :)

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
nvtable: nv_table_realloc() fixed the initialization of the size member

The size member has remained at its old size if there were multiple
refs to the NVTable thus a new allocation occurred. This was
shadowed by the fact that syslog-ng will happily realloc the ref==1
NVTable later on, at the cost of another realloc.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
nvtable: nv_table_clone is fixed to limit NVTable size fo NV_TABLE_MAX_BYTES

This check was omitted, thus nv_table_clone() was able to grow the
NVTable over the allowed limit.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
test_nvtable: added testcases to cover realloc/clone corner cases

This unit test is now a mess, I hope to clean that up one day, otherwise
this improves coverage and adds validation on two, previously uncovered
issues.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logwriter: fixed an infinite loop in LogWriter

This patch fixes a possible infinite loop, when the template expansion
results in a zero-length string. In that case syslog-ng assumed
it couldn't handle the message, sets consumed to FALSE, and puts
the original message back to the head of the queue.

This is a bad idea, as the next time the LogWriter wakes up, it finds
the same message there, does the same thing again and again ad infinum.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Makefile.am: Add PRELOAD_SYSLOGFORMAT and other helpers

Instead of hardcoding the same dlpreopen at many different locations,
add a helper variable to the top-level Makefile.am, and use that
variable in all other places.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
When doing make check in a subdir, use tests from subdirs too

Teach the Mk/subdir.mk snippet to recurse into subdirs of subdirs when
doing make check. This is a bit of a nasty hack, but gets the job done.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Mk/subdir.mk: Support partial installation

When using the wrapper Makefile (Mk/subdir.mk), allow make install to
work from within a subdir. The solution is a bit of a hack, and contains
some hard-coded assumptions, and only works for lib/ and stuff under
modules/, but that's where 99% of the work is done anyway.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Mk/subdir.mk: When running under a subdir of lib/, work on lib

Directories under lib/ (except for ivykis, where this doesn't apply
anyway) are for organisational purposes only, they are used as part of
libsyslog-ng, built from lib/ itself. So when standing in such a subdir,
pretend we're in lib instead.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
configure.in: Remove obsolete macro usage

Use AC_CONFIG_HEADERS instead of AM_CONFIG_HEADER, and drop the use of
AM_PROG_CC_STDC, because these macros are long obsolete, and were
removed from automake 1.13.

Reported-by: Michael Sterrett <mr_bones_@gentoo.org>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
afmongodb: Update the embedded libmongo-client

Update the embedded libmongo-client library to the latest git master, to
pull in a modernised configure.ac and a couple of other fixes.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
afmongodb: Update the embedded libmongo-client again

The embedded libmongo-client needs an update, to fix make dist, this
does just that.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
pacctformat: Fix the constructor

Instead of using a pointer to a function as the constructor, use the
function itself, properly casted, like the rest of the similar
constructors.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Mk/lex-rules.am: Touch the output of the lexer rules

In order not to regenerate lib/cfg-lex.h all the time if cfg-lex.l has
its timestamp updated without any content change, touch the target in
the lexer rules, so that their timestamp gets updated, even if the file
is not regenerated.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Mk/lex-rules.am: Make grammar compilation less verbose

When the grammar is unchanged, hide that, there's no need to show that.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
tests: Add a testcase for template_escape()

In order not to break template_escape() functionality, add a test case
for basic functionality testing.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
templates: Respect the template_escape() in template functions

When a template function creates a template itself, make the new
template inherit the escape setting from the parent.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
.travis.yml: Run func-tests too

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
cfg-grammar.y: Allow defaultless block{} arguments again

When parsing block{} arguments, do not ignore ones where the default
value is empty: that is perfectly valid.

Fixes: #230
Reported-by: Anton Koldaev <koldaevav@gmail.com>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logwriter: fixed a double-free issue in case of a flush error happens

This patch fixes a double-free and possible use-after-free issue in case
an error happens when writing a file on disk. The easiest way to reproduce
is to fill a disk, then wait time_reopen() seconds.

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