lib/iobroker: Make iobroker compile nicely with non-glibc libs

The features.h header file is glibc specific and not present
everywhere, so include it conditionally.

Reported-by: Armin Wolfermann <aw@osn.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2254 5f96b256-904b-4d8d-8c98-d829582c6739
Add and use nsock_printf()

This is a small but nifty helper that writes formatted messages to
any filedescriptor. It may block, so callers should make sure to
poll for writability before using it.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2255 5f96b256-904b-4d8d-8c98-d829582c6739
test-dkhash: Remove vebose flag

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2256 5f96b256-904b-4d8d-8c98-d829582c6739
lib/iobroker: Make it an error to re-register a filedescriptor

Without this patch we would have leaked memory and silently
overwritten a previously registered handler when someone
registered a new handler for the same filedescriptor. Since
multiple input handlers for a single source makes no sense (and
weren't supported earlier either), we simply error out when we
notice that happening.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2257 5f96b256-904b-4d8d-8c98-d829582c6739
nsock: Create non-blocking sockets by default

99 times out of 100, that's what one wants for ipc communications.
When it's not, we provide the nifty NSOCK_BLOCK flag, which can be
passed instead. When fcntl() fails, we return NSOCK_EFCNTL.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2258 5f96b256-904b-4d8d-8c98-d829582c6739
lib/nsock: Add nsock_strerror()

This lets one know with a quick call which of the numerous calls
involved in creating a unix socket failed, which will make any
following strerror() calls make a lot more sense.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2259 5f96b256-904b-4d8d-8c98-d829582c6739
Remove double-newlines in object cache files

The opts2str() variable adds it for us, so we needn't bother
with it when callilng that.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2260 5f96b256-904b-4d8d-8c98-d829582c6739
core: Re-use pre-existing timed_event's for hosts and services

This fixes an extremely intermittent bug which would previously
occur when we happened to get an inbound checkresult from a worker
for an on-demand check of a host while inspecting the timed_event
belonging to that host.

When such a host received a new scheduled item, they used to free()
their current timed_event, only to allocate a new one immediately.
That didn't make much sense, cost us performance, caused the event
execution loop to crash and lost me a full day of hacking on the
general-purpose all-magical superduper ultra-fantastic query handler,
now with extra bling.

As an extra fun thing, it appears this can (well, could) only happen
before all hosts and/or services had been checked at least once, and
only for hosts, and almost certainly only with the pathological check
settings I'm using for testing (2 second interval_length), and most
likely only when the developer is really, really tired of looking at
valgrind (which caused the bug NOT to happen for 900 invocations) and
quite possibly only on rainy wednesdays between 12.30 and midnight...

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2261 5f96b256-904b-4d8d-8c98-d829582c6739
initialize event queue when we're done reading object config

Otherwise we have no idea how large to make it.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2262 5f96b256-904b-4d8d-8c98-d829582c6739
base/checks: Be more careful when creating check results

Using calloc() instead of malloc() means the memory is always
zero'd out before we get it. That small cost is definitely worth
it to avoid having to chase down uninitialized variables in
structs that something thinks is set to something.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2263 5f96b256-904b-4d8d-8c98-d829582c6739
core: Set 'engine' field to NULL when initializing checkresults

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2264 5f96b256-904b-4d8d-8c98-d829582c6739
lib/squeue: Plug a micro-leak

If we fail to insert the squeue_event into the priority queue, we
must free the allocated area or it'll become lost. This patch does
just that.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2265 5f96b256-904b-4d8d-8c98-d829582c6739
base/events: Clean up event handling a smidgeon

Most of these changes were deemed necessary during The Hunt For The
Horrible Bug four commits back. It's a tad cleaner and a bit less
code now, so I assume that's good. We also stop removing scheduled
service checks twice. Many thanks and kudos to Armin Wolfermann for
spotting that and sending the first patch, which caused me to take
a deeper look.

Inspired-by: Armin Wolfermann <aw@osn.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

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