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>
WIP: added a few cases to under_termination

FIXME: why are these needed?
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: factor out I/O worker thread handling to a separate module
mainloop-io-worker: factor out mainloop-worker as a layer

This patch makes it possible to create worker threads that are _not_
processing LogReader/LogWriter I/O callbacks, but can generate messages
as they see fit. This makes it possible to create source drivers
with a dedicated thread very easy.

All the previously LogReader/Writer specific logic was generalized and
two modules were produced:
  - mainloop-io-worker: hosts thin LogReader/Writer specific wrapper
  - mainloop-worker: hosts most of the logic

You can now create a new thread using main_loop_create_worker_thread().

This patch changes all worker threads to be unjoinable, as thread exit
synchronization will be performed using the mainloop provided machinery.
This shouldn't be much of a difference though.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogThreadedDestDriver: use the new main_loop_create_worker_thread() API

This patch adapts LogThreadedDestDriver to use the new
main_loop_create_worker_thread() API that will properly terminate all
threads prior to calling the deinit() method.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
AFSql: use the new main_loop_create_worker_thread() API

This patch adapts AFSqlDestDriver to use the new
main_loop_create_worker_thread() API that will properly terminate all
threads prior to calling the deinit() method.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
misc: remove create_worker_thread() function

It was superseeded by main_loop_create_worker_thread().

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: factor out main thread calling functions to separate module
mainloop: add win32 signal handlers
control: refactor to make place for a win32 implementation

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
control: add win32 implementation for control channel

Signed-off-by: Viktor Juhasz <jviktor@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: refactor signals to use a small helper function

That makes the signal setup code easier to read.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: refactor event registration to use a small helper function

This patch makes mainloop_init_events() to be easier to read.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
apphook: move res_init() to app_post_config_loaded()

Instead of pulling in more dependencies to mainloop, use apphook to
reinitialize the system resolver at every SIGHUP.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop: remove unneeded headers

With the latest mainloop refactor a great number of header inclusions
could be removed. This patch does exactly that.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
mainloop-worker: remove worker thread signal setup

We used to require SIG_BLOCKing a number of signals in worker threads as
we pretty much relied on SIGHUP/SIGTERM/SIGCHLD/SIGINT to arrive to the
main thread. This is not guaranteed by POSIX however.

In POSIX signals are delivered to a process, and the OS is free to choose
a random thread to deliver that signal to, assuming the signal is not
blocked there.

That was the reason we blocked these signals everywhere except the
main thread.

Stuff however changed when we switched to a multithreaded architecture and
started using libivykis. ivykis pretty much handles this just fine by
rerouting signals to callbacks in the thread that registered the interest.

That way, it doesn't really matter which thread the signal is delivered
to it is taken care of.

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


Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
merge: with reload/terminate API