lib/bitmap: Allow unions between one set and the empty set

Previously we required two valid bitmaps to be passed to bitmap_union
and bitmap_unite, but taking the union of a set and the empty (NULL)
set is a valid operation that yields "the other" set. unioning two
empty sets ofcourse yields the empty set, so we're covered from all
angles.

Signed-off-by: Andreas Ericsson <ae@op5.se>
base/config: Print number of checked host/service dependencies

We used to do that when we verified the data in them, and now we do
it again when we assure their acyclicity (if that's not a word, it
should be).

Signed-off-by: Andreas Ericsson <ae@op5.se>
Revert to old-school group recombobulation

Group recombobulation turned out to be a tad trickier than I first
thought, and while it's broken a lot of people are unable to test
Nagios 4 in any sort of long-running scenarios.

Unortunately, the dfs dependency patch ended up with the first
implementation on one side of the buggy recombobulation patch and
the fix of the first implementation on the other side, meaning
noone could really test any of it properly.

To get a clean revert, we also remove the buildfix for the group
recombobulation patch.

This reverts the following commits:
2059816f862b36598ce5301156f8a3c621712f9a
  Make cgi's compile with new group recombobulation code
abe461837d1a0955ef64d714b318e11a1a19cf18
  xdata/xodtemplate: Fix group recombobulation"
base/config: Fix free()'ing of arrays in pre_flight_circular_check()

With high levels of optimization, the compiler would unroll the loop
and could yield code that tries to free() array subscripts with
negative numbers. We restrict the test to make sure the index never
goes below 0 and decrement it before checking to restrict the
compiler not to unroll that particular loop.

Signed-off-by: Andreas Ericsson <ae@op5.se>
common/objects: Avoid using uninitialized memory

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/skiplist: Plug a memory leak on duplicate inserts

Previously we used to allocate space for the new entry before we
checked if it was unique. With this patch we can return an error
before we take any memory and thereby avoid leaking it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Remove macro for hostgroupescalations

It was an internal one and they haven't been around for a long time.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Return of the recombobulation fixes

This is the next algorithmic step towards making config parsing as
quick as possible. The valgrind numbers are from a config with 1k
hosts, 10k services and 7 servicegroups, where services are assigned
to servicegroups using the 'servicegroups' directive from the service
themselves. This seemed to be the worst way to do it, apart from
creating insanely long template inheritance chains and achieve
much the same thing through that. The /usr/bin/time numbers are from
a config created exactly the same way but with 10k hosts and 100k
services. I did do a valgrind run on that setup with the old code
once but had to let it run an entire night to get numbers, and I
didn't save them.

Without patch (valgrind + /usr/bin/time, relevant figures):
heap usage: 711,866 allocs, 711,849 frees, 647,021,086 bytes allocated
48.86user 1.24system 0:51.25elapsed 97%CPU (0avgtext+0avgdata 222544maxresident)k
6856inputs+536outputs (2major+1232198minor)pagefaults 0swaps


With patch (valgrind + /usr/bin/time, relevant figures):
heap usage: 546,172 allocs, 546,149 frees, 26,950,412 bytes allocated
8.50user 0.20system 0:08.91elapsed 97%CPU (0avgtext+0avgdata 218960maxresident)k
0inputs+528outputs (0major+41675minor)pagefaults 0swaps

So not only do we process objects 5.7 times faster. We also use less
memory to do so. The speedups seem primarily related to the number of
memory allocations and string operations we do, which can ofcourse
be improved further. Both cores were compiled with -O0 and -pg to get
profiling numbers, so function call overhead is overemphasized and
skews the results somewhat in favor of the old code, which still
loses by a large margin.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Reduce memory usage when parsing config

Using full integers to mark the "have's" of objects makes little sense,
since we only use one byte of them. With this patch, we reduce the
size of all xodtemplate_* objects. A lot of hosts and services and a
little for the others (done mostly by sed, so some of it makes very
little sense, but still get applied). We do this by adding bitfields
for the true booleans that never get passed by address (since bitfields
don't have addresses), saving us a neat 17megs of max rss for 10k
hosts and 100k services. Not too shabby for two minutes of work with
sed.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Reduce memory usage from object config parsing

Since the group recombobulation fixup, we always duplicate objects
using the pointer to the master object's name variable, which will
get free()'d later. By marking which objects are the copies, we
can thus get away without duplicating quite so many strings, and
thereby save ourselves another 20-ish % of both runtime and memory
usage during config parsing and resolution time.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Officially (and loudly) deprecate extinfo objects

We want to get rid of them at some point, but they get to linger
on for a while longer so we have the blaring-trumpets-period of
deprecation.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Make sure to stash next_check_event for hosts and services

I stumbled on this by accident. It looked wrong and the fix is
obviously correct, so we might as well apply it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Bring host and service objects a little bit closer to each other

We do this by ironing out the differences between them, starting with
some that have no logical meaning what so ever.

services:
	last_notification     -> last_notification
	next_notification     -> next_notification
	obsess_over_service   -> obsess
	service_check_command -> check_command

hosts:
	last_host_notification -> last_notification
	next_host_notification -> next_notification
	obsess_over_host       -> obsess
	host_check_command     -> check_command

Unfortunately, we can't provide backwards compatibility macros for
the last_host_notification and next_host_notification macros,
since contacts have the same variables and it would ruin the build,
but these changes are non-invasive enough that mod authors should
be able to cope fairly easily.

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/squeue: Make sure we work well on 32-bit systems

Previously on 32-bit archs gcc would issue the following warning:
	squeue.c:34:  warning: left shift count >= width of type

which is legitimate, because unless we explicitly cast the
return type we'll do math on 32-bit values, which clearly can't
be shifted 32 bits or more.

With this patch we break the math apart so we always operate on a
type large enough to support it. For those weird systems where
'unsigned long long' is not 8 bytes wide, we do our best by simply
using the 32 bits at our disposal to store the timestamp.

Reported-by: Ricardo Maraschini <ricardo.maraschini@opservices.com.br>
Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/dkhash: Don't oversize tables so enormously

For small inputs, rounding up to the nearest power of two seemed like
a sensible idea, when it quickly escalates the memory usage beyond
reasonable limits when we have, say, 1.1million objects (when we would
allocate 2^21 buckets for the hash table, ending up overallocating by
a *huge* amount).

With this patch we pay the 'modulo price' and let the caller decide
the size of the hash table, which should (for preference) be x1.5
of the number of objects one wishes to store in it.

While at it, we refactor the dkhash_create() routine a bit to make
it less deeply indented.

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/skiplist: Doxygen document skiplist.h

... and remove the unused "skiplist_delete_all()" function.

Its current only use is to be called immediately by skiplist_delete()
and as such it's quite useless.

Signed-off-by: Andreas Ericsson <ae@op5.se>
xdata/xodtemplate: Remove a lot of dead code

This removes the pretty ancient insertion sort algorithms used
prior to the addition of the skiplist libraries, which rendered
the former useless, as well as some of the timing values that
are no longer printed or even calculated.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Add some doxypages with technical documentation

The pages primarily list incompatibilities between Nagios 3 and 4,
but may well be used to house technical documentation later.

Signed-off-by: Andreas Ericsson <ae@op5.se>
base/events: Remove double variable assignment

Patched-by: Ricardo Maraschini <ricardo.maraschini@opservices.com.br>
Signed-off-by: Andreas Ericsson <ae@op5.se>
skiplist.h: Fix doxy comments

Apparently we missed the @file marker, so doxygen didn't parse it
after all.

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