test_hostname: use the same kind of mocking when WRAP_GETHOSTNAME is set

WRAP_GETHOSTNAME is used within this unit test to actually run testcases
against my own laptop's DNS settings.  It used to simply link against
libsyslog-ng.so, while the alternative compilation included the hostname.c
source file directly.

This patch changes the test program to always include hostname.c

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
apphook: call msg_init() first

As the hostname module was initialized prior to messages, it couldn't emit
internal messages until now. This patch fixes this by moving msg_init/deinit
around in app_startup()/shutdown()

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
hostname: fix abort when the local hostname is unknown to both DNS and /etc/hosts

When the local hostname is not an FQDN, syslog-ng consults the local
resolver to get a fully qualified domain name from either the DNS or the
hosts file.

Previously if this failed, syslog-ng aborted after printing an error
message. This patch changes behaviour so that in this case syslog-ng
will happily work with the non-qualified hostname after printing
a notice to the internal() log.

This was triggered by a SUSE test environment, so this actually happens.

Reported-By: Peter Czanik <czanik@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
hostname-unix: find the first non-FQDN name, instead of always picking the primary name

The primary name of a host should always be FQDN, especially when it is
resolved from DNS. Even the hosts file should list the FQDN first. With
this assumption, syslog-ng used to pick the primary name, always.

So with an inconsistent configuration, where /etc/hosts listed the FQDN
at the non-first position, syslog-ng picked the wrong name.

This patch changes the logic and finds the first FQDN. This patch also
refactors hostname-unix a bit and covers the hostname extraction function
with testcases.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
messages: only try to emit an internal() message if post_func is set

During early startup, an internal message might be triggered by syslog-ng
while the internal() fabric is not yet in place, which caused a SIGSEGV.

In this case, warning (and above) messages were printed to stderr, but
anything below warning used the normal LogMessage based code path, which
segfaulted as log_msg_global_init() was not yet called.

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