contrib/systemd: Alias the service to syslog.service

In order to be considered a syslog service, we need to Alias ourselves
to syslog.service. Doing this will make systemd consider syslog-ng a
valid syslogd service, without the alias, one has to do something
similar manually.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
scl: Teach the system() source about systemd

On Linux, when LISTEN_FDS is non-empty, and
/run/systemd/journal/syslog is a socket, assume we are running under
systemd, in which case our source shall be the journal's syslog
output, instead of the default /dev/log.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
libsyslog-ng-crypto.so: link against libcrypto explicitly

This patch adds OPENSSL_LIBS to LIBADD so that libsyslog-ng-crypto.so is
always linked against libcrypto.so

Reported-By: Alexander Komyagin <komyagin@altell.ru>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
lib/gprocess.c: Ignore SIGHUP inside the supervisor.

Reloading syslog-ng's config is often done via a killall -HUP
syslog-ng command, which also sends a signal to the
supervisor. However, the supervisor did not handle said signal, thus
it exited as is the default for it.

To work around this issue, lets ignore SIGHUP inside the supervisor.

Reported-by: Patrick Hemmer
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
afsocket: Support a smooth upgrade path to recent systemd

When the journal was introduced in systemd, it started to pass
/run/systemd/journal/syslog to syslogds (it was passing down /dev/log
before). Since we verify that the FD to open matches the expected
filename, we didn't pick up the fd due to the filename mismatch.

This can be fixed on the system() source level, where it can decide
which to generate into the config. However, for setups that do not use
system() for one reason or the other, this does not work.

For these systems that do not use the system() source, the best
solution is to try and replace /dev/log with
/run/systemd/journal/syslog at run-time. This patch does just that,
and ties it to config versions 3.4 or earlier.

This means that post-3.4, the automatic replacement will stop working,
and users will get the generic failed to acquire socket error message
instead.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Don't use deprecated glib symbols on newer glibs

A couple of symbols have been deprecated by glib in versions newer
than the minimum version syslog-ng supports, and with 2.30 which
deprecated g_atomic_int_exchange_and_add(), these warnings are way
over the normal threshold, and turn build logs into not much more than
noise.

The three deprecated functions and their fixes are as follows:

 + g_atomic_int_exchange_and_add(): Which is replaced by
   g_atomic_int_add() if the glib version is found high enough at run
   time.

   This is a single place to add an ifdef to, and doing it any other
   way would be far messier.

 + g_mapped_file_free(): This is replaced by g_mapped_file_unref(),
   and a configure check was added to see if _unref() is available. If
   it is, we use that. If not, we alias _unref() to _free() in
   compat.h. This way, the call sites can always use
   g_mapped_file_unref().

 + g_strup(): This has been deprecated so long ago, that no check is
   done, the code was rewritten to use g_ascii_strup() instead.

No functionality is lost or changed, just different interfaces used to
accomplish the same thing.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
logproto: Move fsync() from logtransport to logproto

To restore the fsync(yes) functionality, move the fsync() from
LogTransport to LogProto instead, so that we can fsync() right after a
write() or writev() call.

Turning on fsync(yes) will now result in log_proto_file_writer_new()
setting self->fsync to a non-zero value, which in turn will cause both
functions that call write() to fsync() right afterwards too.

Reported-by: Patrick Hemmer
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
scratch-buffers: Fix a compiler warning

Include misc.h for g_string_steal(), so that the compiler stops
complaining about an implicit declaration.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
rpm: Do not try to install the removed README

Reported-by: Mark Ulmer <mark.ulmer@apollogrp.edu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
tests: Include /usr/lib64 in the dbd search path

Certain systems put 64-bit libraries into /usr/lib64, so include that
directory in the dbd search path for the tests. Thanks to Jose
Oliveira <jpo@di.uminho.pt> for the patch!

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
LogWriter: rename message duplication related functions

This makes their goal easier to understand.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
afuser: Use utmpx when available, instead of utmp

FreeBSD 9 removed support for utmp, and one must use the
POSIX-specified utmpx instead. The same utmpx is available on Linux
too (and it is the same as utmp there).

The patch below converts afuser to use utmpx when available, utmp
otherwise. It is based on the post-build sed magic applied to
syslog-ng within the FreeBSD ports collection, with other bits based
on a patch from Alex Zimnitsky.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
dnscache: Fix a memory corruption when destroying the DNS cache

The DNS cache gets destroyed every time a worker thread quits, which
is fine, as most of the dns cache variables are thread local.

However, dns_cache_hosts is not, it's a global static, and
dns_cache_destroy() was freeing that aswell.

The solution is to not free dns_cache_hosts when a worker stops, but
do so when syslog-ng stops. This patch introduces dns_cache_deinit()
which does just that, and removes the same thing from
dns_cache_destroy(), which now only touches thread-local variables.

Reported-by: EgonB <egon@local.ee>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
[doc/Makefile.am] Add the xsd/patterndb-4.xsd to the install definition

The definition for the xsds overlooked the new version 4. Added the
xsd/patterndb-4.xsd to the xsd_DATA definition so that make install
will install all 4 xsd definitions.

Reported-By: Evan Rempel <erempel@uvic.ca>
Signed-Off-By: Evan Rempel <erempel@uvic.ca>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
lib/eventlog: Remove the lib/eventlog submodule

It accidentally went in with an unrelated change, and was never really
hooked in.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
lib/ivykis: Point the submodule to github

Point the lib/ivykis submodule to github.com/balabit/ivykis instead,
and update it to the most recent commit.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
cfg-lexer: Split cfg_lexer_include_file() into two functions

To be able to keep the code simple in the future, split
cfg_lexer_include_file() into two: the intent is that we'll check if
the file exists, and if not, try the same thing as a glob, otherwise
continue as we did before.

This would nest too deep, so split out the current bulk into a
separate function.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg-lexer: Implement glob-based @include.

Both for distributions and otherwise, the ability to limit what kind
of files are included, especially when doing a directory include is
very important.

This patch implements just that, by extending cfg_lexer_include_file()
to try and resolve globs, if it can't find a file otherwise. Files
included this way still respect the global include-path setting, so
@include "foo.d/*.conf" will still work.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
systemd: No need to stop systemd-kmsg-syslogd anymore

When the Journal was introduced, systemd-kmsg-syslogd.service was
discontinued, so there is no reason to try and stop it anymore.

Reported-by: Jose Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
systemd: Add a Documentation= field to the unit file

This will allow systemctl help syslog-ng.service to bring up the
manual page.

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