lib: Make NAGIOS_DEPRECATED work for compilers older than gcc 4.5.0

The optional message argument to the deprecated attribute was added
in gcc 4.5.0, so older versions of gcc fail to build Nagios without
this patch.

As a neat side-effect of how we implement the thing, we also get a
NAGIOS_MKVERSION() macro, which can be used to set API versions for
various parts of Nagios and libnagios, which will come in handy for
handling incompatibilities.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2692 5f96b256-904b-4d8d-8c98-d829582c6739
Macros: fix of invalid free for TOTALHOSTSERVICES* macros

The $TOTALHOSTSERVICES*$ macros were computed all at the same time, with the
result stashed in mac->x using the mkstr method (from worker.c? why worker.c?)

The mkstr uses an static internal buffer of usally 256 strings, of each 32
bytes, for generation of strings, used in macros. When computing
TOTALHOSTSERVICES*, the valuse is, as said, stashed in mac->x[], which is freed
 at cleanup, with some exceptions, and this isn't one of them.

Those needs to be exceptions, so static function variables isn't freed

Signed-off-by: Max Sikström <msikstrom@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2693 5f96b256-904b-4d8d-8c98-d829582c6739
worker manager: Introduce wproc_run_callback()

This lets modules run checks and external helper commands without
them necessarily passing through Nagios check-handling routines,
which was earlier the only way modules could see the result of the
external command they wished to run.

It's also neat in that it allows one to write a small module that
manually tests a particular command by using Nagios' internal escaping
mechanisms, which can be incredibly handy when configuring commands
that look more like awk scripts than normal unix commands.

Original-patch-by: Max Sikström <msikstrom@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2694 5f96b256-904b-4d8d-8c98-d829582c6739
core: Log an error when we fail to parse a worker buffer to a kvvec

A fixme comment with an actual oneline fix. That's just plain odd.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2695 5f96b256-904b-4d8d-8c98-d829582c6739
libnagios: Add the 'fanout' api

Fanouts are useful to hold expiring 'long'-indexed data where
the span between smallest and largest key can be too large and
change too often for it to be practical to maintain a "real" array.

For Nagios, that currently matches downtime, comments, and jobs
assigned to worker processes, where either linked lists or some
form of dynamic array lookup is done today.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2696 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Assign job-list management to libfanout

It was by far the clumsiest code in the worker manager, and since
clumsy code tends to harbor bugs, we replace it with the elegant
and obviously correct code in libfanout.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2697 5f96b256-904b-4d8d-8c98-d829582c6739
core: Make sure configured logfile always trumps default one

Previously we could end up logging to the default location if we
had deprecated variables defined before we defined log_file (which
caused us to write to the log_file set as default at compile time),
but the logging api is clever enough to keep that file open and
won't reopen it unnecessarily.

With this patch, we always close the log_file whenever we run into
the log_file statement, which causes the logging api to reopen it
with the new (and correct) path whenever we want to log something
again.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2698 5f96b256-904b-4d8d-8c98-d829582c6739
core: Log deprecated variables to the 'final' logfile

The previous patch made sure we started writing "real" logmessages
to the right place, but could still cause some logmessages to end up
in the wrong logfile. With this change we protect against that by
adding deprecated variables to a list and printing their warnings
when we're done parsing the entire file (which means we've always
parsed the 'log_file' statement).

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2699 5f96b256-904b-4d8d-8c98-d829582c6739
core: Check timeperiods for circular exclusions

Doing the exclusion logic right means traversing all the exclusions.
If there are circular paths there we might be at it for ever, which
is bad. With this patch we know we don't need to bother checking it
in the timeperiod handling code, which is messy enough as it is.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2700 5f96b256-904b-4d8d-8c98-d829582c6739
cgi: Fix null pointer reference in getcgi.c language selection

Reported as issue 434 to tracker.nagios.org, this only happens on
solaris, where the printf() family functions aren't helpful enough
to replace NULL pointers with the string NULL rather than bombing
out.

While at it, we rename the input parameter so it doesn't collide
with a typename we want to use.

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

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

Stash next pointer for entry when iterating over a linked list in
the "obviously correct" fanout lib.

The next pointer is lost when freeing the entry item in a for loop...
A penny^H^H^H^H^Hpointer saved is a pointer earned, as my grandma used
to say.

Signed-off-by: Max Sikström <msikstrom@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2702 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-runcmd: Make it build with new runcmd flags

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2703 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-nsutils: Update to use the defined functions

Way back I intended to give these utils a common prefix, and the
prefix lived on in the tests but not in the commit that actually
introduced the commit. Bad, bad Andreas...

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2704 5f96b256-904b-4d8d-8c98-d829582c6739
Add lib/test-fanout.c

It's obvious that even obviously correct code sometimes has really
obvious bugs, so obviously we need some sort of testing to make
sure the obviously correct code does the obviously correct thing.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2705 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-kvvec: Add a test for kvvec_capacity

It was the last untested function of the kvvec library, so now we
have full coverage there. Neato.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2706 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-iobroker: Also test iobroker_is_registered()

We run the test on removal and addition, which means we now test
to make sure the iobroker handles internal state exactly as
intended.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2707 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-dkhash: Flesh out with more tests

The counter-functions, among other things.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2708 5f96b256-904b-4d8d-8c98-d829582c6739
lib/test-bitmap: Flesh out bitmap tests a bit

More precise tests for intersections and a lot more coverage, for
example. If bitmap_unset() and bitmap_clear() fail, the config
parsing will be severely fouled up.

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

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