base/events: Don't get stuck in busy-wait loop when poll returns EINVAL

In a couple of instances, by completely breaking libnagios, I've managed
to create situations where there are no workers connected to nagios.
When that happens, nagios would get stuck in an infinite loop, where
polling for events always returns -1 (EINVAL) immediately, and nagios
would respond to that by immediately trying again, making my machine
warm and tired. Exiting the event loop when that happens seems more
reasonable - we can't run any more checks, and we can't notify anyone
about this, because we have no worker to do so for us.

It would be possible to set sigrestart to TRUE, to force nagios to
restart all its workers again, yet this could create the same crash loop
that I'm trying to fix, only somewhat larger and slower - if all sockets
died, something is seriously broken, so make it possible for an external
watchdog daemon to find out.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2451 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Fix crash when freeing the last core worker

When freeing the last core worker, we'd set the worker list to NULL, yet
keep the list len at 1. This caused free_worker_memory to try to lookup
workers from NULL, creating a SEGFAULT.

By always decrementing len, even when we're destroying the last worker,
we'll actually realize that we're out of workers, leave NULL alone, and
shut down cleanly.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2452 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Fix detection of check basename for special workers

strrchr may search from the end of the string, but it still expects the
pointer it is provided to point to the beginning of the string. Thus, we'd
only check if the last byte was a slash, rather than for the last slash.

Manipulating the cmd_name for basename discovery is unnecessary, so
don't.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2453 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Create pqueue event before shipping child proc over to cb

It's quite possible to build a worker so that it doesn't have to work
asynchronously (or can work very, very, very fast), so that it will call
finish_job before we've finished setting up the child process, which
will cause random memory access errors that can cause worker crashes.
By finishing setup before handing over control to the worker callback,
we can close that possibility.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2454 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Be less loud when using specialized workers

The fact that we didn't handle the job like usual is interesting, but
not quite /that/ interesting that we need it logged once per check -
let's convert that log message to a debug message.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

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