core: Never try to start a negative number of workers

Doing so would be pretty futile, even if a user explicitly
requested it.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2526 5f96b256-904b-4d8d-8c98-d829582c6739
core: Make all query handler errors hard ones

We rely on it pretty heavily now that workers connect through it,
so if it doesn't work properly we must log it and return an error
to our caller.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2527 5f96b256-904b-4d8d-8c98-d829582c6739
core: Make qh_init() failures fatal

We absolutely must have the query handler around if our workers are
supposed to be able to register with us, so without it we're very
much blind.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2528 5f96b256-904b-4d8d-8c98-d829582c6739
qh: Fortify removal of registered handlers

We want to remove registered handlers from the (now doubly) linked
list of registered handlers, as well as making sure that 'qhandlers'
always points to the first entry if there are any or is NULL in
case there's not.

This patch makes it so, meaning the rest of Nagios, including its
modules, can safely register handlers upon initialization without
having to double-check if the error they get back is because they're
already registered or if it's due to something more serious.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2529 5f96b256-904b-4d8d-8c98-d829582c6739
core: deinit query handler immediately upon exiting event loop

Delaying deinitialization may mean we may end up removing a
handler for a module, in which case we won't be able to access
the string used as key into the hash table.

Without deinitialization, the query handler help listing can
get duplicate entries of the same handler.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2530 5f96b256-904b-4d8d-8c98-d829582c6739
qh: Handle the query '#help help' nicely

We used to end up in an infinite recursive-function loop, consuming
all stack space after some 30000 (nested) function calls. We also
used to be younger and like butterflies more.

This fixes the former. For the latter, there's no help.

Reported-by: Daniel Wittenberg <dwittenberg2008@gmail.com>
Originally-fixed-by: Robin Sonefors <rsonefors@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2531 5f96b256-904b-4d8d-8c98-d829582c6739
qh: Set qh_table = NULL when deinitializing the queryhandler

This ensure that we never end up in a situation where we get queries
in between deinitializing all handlers and re-enabling the handler
altogether.

I'm not sure if we really *can* end up in such a situation, but if
we can't now then it's an at least theoretical possibility in case
the linux kernel folk decide to change how epoll() works. It may
also matter for the case where we're using something other than epoll.

Anyways, this is a belts-and-suspenders-and-tidyness patch, and it
definitely won't hurt anything, so let's apply it.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2532 5f96b256-904b-4d8d-8c98-d829582c6739
core: Make debugging coredumps infinitely more pleasant

The fact that gdb can never find the files we demandload is pretty
damn annoying. With this patch we make no great architectural changes,
but we do make a double copy of the module, so that a file with its
exact contents exist at the place where we loaded it from, but with
a different inode.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2533 5f96b256-904b-4d8d-8c98-d829582c6739
nerd: Name our in-core module 'NERD' as filename

Since we normally log the filename of the module when initializing
and deinitializing modules, we might as well abuse the fact and name
our module 'NERD'. Since it's a core module, we'll never *really* try
to load that (hopefully) nonexistant file, but at least we'll stop
printing "Successfully deinitialized (null)", which just looks weird.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2534 5f96b256-904b-4d8d-8c98-d829582c6739
objects: next_check_event member of struct host is a timed_event

It's always used as that, and never as anything else. This patch
makes sure the compiler warns us if we try to do something silly
with it. Any modules that tried to use it as anything else would
have either caused Nagios to crash, or failed to do its job, so
this isn't actually an ABI change (as the object size remains
constant), but an ABI bugfix which just lets the compiler help
us more, and getting less in our face in case we forget to cast
the damned thing to the timed_event it really is.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2535 5f96b256-904b-4d8d-8c98-d829582c6739
nebmods: Don't free core module's filenames

Doing so breaks, since they're supposed to use static names there
that simply identify them in the logs.

Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2536 5f96b256-904b-4d8d-8c98-d829582c6739