mainloop: factor out systemd communication into a service-management module

Some communication takes place between syslog-ng and systemd after
the former has started. We indicate when initialization at startup
finished and also some textual messages to indicate our state.

Earlier it was right in the middle of the mainloop code, now factor it
out to a separate module, perhaps this interface can be useful
for other similar implementations.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
main: move app_startup() to the main function

Instead of invoking it in main_loop_init().

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: move signal setup code to setup_signals()

Some of the signal setup code was in main_loop_run(), move that to
setup_signals() as that function is meant to set up signals.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: factor out stats timer to a separate module

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: add calls to initiate config reload/termination

This patch adds a public API to initiate reload and termination from
within syslog-ng, rather than using only signal handlers to do so.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
apphook: add per-thread start/stop functions

This patch adds two functions to apphook, one to be invoked at every
thread creation and its pair to be invoked when a thread is about to exit.

This decreases the level of coupling on code that actually spawns threads.
A dynamic registration would be even nicer, but this is what we have for
now.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: export main_loop_is_terminating variable

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