Plug a leak in common/objects.c

It seems I forgot to remove the separate object allocation for
serviceescalations when I did the "one allocation" patch. This
remedies that and makes "nagios -v -s" once again leak-free.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2117 5f96b256-904b-4d8d-8c98-d829582c6739
Remove incomplete failure prediction code

Failure prediction analysis is difficult and requires knowledge of
plugin values. One of the very strong points about Nagios is that
it doesn't have to care about plugin output (beyond storing and showing
it), so adding failure prediction on a global scope makes very little
sense. It would be doable by something that recognizes performance data
and can spot trends in such data. That's an excellent task for an
addon, but we'd do better not to riddle the core with such code.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2118 5f96b256-904b-4d8d-8c98-d829582c6739
common/objects.c: Never free() objects taken from pre-allocated lists

Doing so will cause the entire block to be free()'d, and thus
invalid for future references. This was supposed to go in the
one-time allocation patch, but apparently I missed these back then.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2119 5f96b256-904b-4d8d-8c98-d829582c6739
common/objects: Fix freeing contacts

Contacts used the 'i' variable when looping over objects, which
caused the iterator to jump up to seven the first time we iterated,
and then stay there for the remainder of the time. This triggered
a nasty bug where we'd go into "undefined behaviour" (often an
infinite loop or a coredump, as it turns out), when freeing contacts.

This bug only triggered when there was more than seven contacts in
total, which made it pretty hard to find at first.

The fix is simple though. We add a new iterator variable for the
contact addresses and use that when freeing them.

While at it, we remove an invalid free(), which was hidden by the
bug mentioned above.

Many thanks to Mike Guthrie and Ken Menzel who provided me with test
configs, as well as to Mark Frost who fixed the config anonymizer.

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

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

When we have better ways of ensuring uniqueness in a linked list,
we might as well not traverse the entire thing every time we add
something to it, but having this little helper is nifty for those
occasions.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2121 5f96b256-904b-4d8d-8c98-d829582c6739
xdata/xodtemplate: Fix group recombobulation

Previously we used to strcat() increasingly huge strings together.

With this patch, we create lists immediately instead. We could
actually improve even further upon the config parsing time by
registering group-contained objects before we recombobulate the
groups, but with this patch things seem pretty fast enough.

The one downside is that members are written in reverse order
in the precache and objects.cache files, but nothing (that I
know of) really cares about that, so I won't either. If it turns
out to be a problem, we can use the slow linked-list insertion
sort already present, but that would be slower.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2122 5f96b256-904b-4d8d-8c98-d829582c6739
Make cgi's compile with new group recombobulation code

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2123 5f96b256-904b-4d8d-8c98-d829582c6739
xdata/xodtemplate: Fix host and service dependency counting

Previously we would allocate too little space for dependencies if
they were assigned to groups, since we failed to take into account
the duplicated dependencies. This patch fixes that, avoiding the
invalid writes we issued earlier that lead to (very) undefined
behaviour when we tried to handle whatever data we accidentally
overwrote.

Many thanks to Mark Frost for helping me locate this bug.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2124 5f96b256-904b-4d8d-8c98-d829582c6739
contrib: Make stuff build properly with libnagios

Thanks to Daniel Wittenberg for keeping an eye on me ;)

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2125 5f96b256-904b-4d8d-8c98-d829582c6739
Remove failure_prediction options from test and sample configs

Patched-by: Daniel Wittenberg <dwittenberg2008@gmail.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2126 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2127 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2128 5f96b256-904b-4d8d-8c98-d829582c6739
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"

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2129 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2130 5f96b256-904b-4d8d-8c98-d829582c6739
common/objects: Avoid using uninitialized memory

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2131 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2132 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2133 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2134 5f96b256-904b-4d8d-8c98-d829582c6739
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>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2135 5f96b256-904b-4d8d-8c98-d829582c6739
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>

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