afprog: Set the process group of the created child

When forking off a child process, set its process group to its PID, so
killing the whole process group in deinit will work. This means that
programs started by the program() source or destination() are now
correctly terminated on reload and exit.

Reported-by: Ryan Frederick
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
modules: Fix the initialisation of LogThrDestDriver modules

All of the LogThrDestDriver modules were calling
log_threaded_dest_driver_init_method() first thing, but that depends on
variables set later, leading to crashes on reload. This patch moves the
call of said method to the end of the init functions, just before the
thread start call. This also requires the _init_method() to be split: we
need to call the LogDestDriver init method at the start of the module
_init(), so that was taken out of LogThrDestDriver, and moved to the
destinations.

Reported-by: Balazs Scheidler <bazsi@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logthrdestdrv: Move the thread start into init_method

Now that we call _init_method() at the end of the module's _init()
function, we can bake the thread start into
log_threaded_dest_driver_init_method(). All users of LogThrDestDriver
updated too.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
loggen: Remove an unused variable

The counter variable in gen_messages() was unused, and causing a
spurious compiler warning, get rid of it.

Reported-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
linux-kmsg-format: Silence glib deprecation warnings

Include syslog-ng.h in the test case, to silence glib deprecation
warnings.

Reported-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
cfg-lex.l: Fix a compiler warning

In cfg_lexer_start_block_state(), use sizeof(gchar[2]) instead of trying
to call sizeof() on the source - even though they're the same thing,
calling sizeof on the source confuses gcc.

Reported-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Reported-by: Michal Privoznik <miso.privoznik@gmail.com>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
tlscontext: Switch verify_mode to gint

We do not use discrete values for TLSContext->verify_mode, but we
combine TLSVerifyMode values instead. Thus, switch the variable to gint
to reflect this, and to silence a compiler warning.

Reported-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
dbparser: Fix parallel builds

Add a missing dependency to the Makefile, so that the build can properly
be parallelised.

Reported-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Makefile.am: Include autogen.sh in the tarball

Requested-by: Jose Pedro Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logthrdestdrv: Rename _init_method() to _start()

Rename log_threaded_dest_driver_init_method() to
log_threaded_dest_driver_start(), as that reflects better what the
function does.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Mk/lex-rules.am: Install the target directory too

Before redirecting the output of merge-grammar.pl, install the target
directory. This makes it possible to build in a deeply nested
sub-directory.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logmsg: fix race condition in log_msg_refcache_stop()

This patch fixes a potential race in log_msg_refcache_stop() that happens
as the last references to a LogMessage instance get dropped.

Previously logmsg_current may have been freed by a parallel thread
by the time we call the ack callback as we folded in the ref counter
differences right before calling ack ref and nothing ensured that
log_msg_refcache_stop() still has at least one reference past that.

The solution was to take a ref first and unref that for as long as we need
that reference.

Unfortunately this requires a second atomic operation every time
log_msg_refcache_stop() is called, which was optional until now.

NOTE: having this patch committed, we might as well simplify the
ack + ref counters as no call sites actually change the two at
the same time.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
json: Parse NULL types too

Null values are allowed in JSON, json-c can parse them, we should just
ignore them, without a warning. This patch does just that, so things
like the following will now go through error-free:

{"MESSAGE": "hello", "something": null}

Reported-by: Nicolas Szalay <nico@rottenbytes.info>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logrewrite: Make the message writable earlier during subst()

When using a subst() rewrite rule, make the message writable sooner, to
avoid an assertion during the substitution process.

Reported-by: Nicolas Szalay <nico@rottenbytes.info>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
NEWS: Preparations for 3.5.0rc1

NEWS & VERSION updated to 3.5.0rc1.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
mongodb: Update libmongo-client to latest master

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
syslog-ng.pc.in: Add -lsyslog-ng to Cflags

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
doc: Allow disabling the manual page building

If xsltproc is not found, or --disable-man-pages is passed to configure,
don't build the man pages.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
LogProtoServer: fixed a use-after-free after reload

self->options is a borrowed memory area, managed by the owning driver
that constructed the given LogProtoServer instance. During reload however,
the driver object itself is freed, while the LogProtoServer instance
is kept alive, thereby causing the options pointer to point into the
void.

The solution is to update the options pointer whenever the owner is changed,
chaining into a similar solution in the LogReader code which does exactly
that.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
dbparser: fix memory leak on reload

At init time a reload was forced, but erroneously a new PatternDB instance
was created and the old one leaked. This is obviously not good for
a number of reasons:

 1) memory leak
 2) db-parser() forgot its correllation state
 3) db-parser() forgot its idea of the current time

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