lib/iobroker: Set iobroker_fds to NULL when we destroy it

In case someone misuses this and fails to NULL out the broker
set, we may end up trying to free() and already free()'d
variable.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2364 5f96b256-904b-4d8d-8c98-d829582c6739
core: Plug some micro-leaks

This makes valgrind output a lot more pleasant to look at.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2365 5f96b256-904b-4d8d-8c98-d829582c6739
nebmods: Implicitly null-initialize new_module when we allocate it

Using calloc() takes care of that, and silences a valgrind warning
about conditional jump depending on uninitialized value.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2366 5f96b256-904b-4d8d-8c98-d829582c6739
core: Plug a minor memory leak and fix some invalid memory accesses

Accessing memory that's already free()'d leads to undefined behaviour.
If the free()'d memory is small enough and it's not claimed by some
other part of the program, that behaviour is usually the same as
acting as if the memory wasn't free()'d at all (ie, no sweat), but
it's retarded to rely on that, so we make sure to fix it.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2367 5f96b256-904b-4d8d-8c98-d829582c6739
query-handler: Plug a leak when registered handlers take over a socket

I created the QH_TAKEOVER return code for this exact purpose, but it
was never implemented. With this patch it's possible to stop leaking
memory when a connecting process is taken over by one of its handlers.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2368 5f96b256-904b-4d8d-8c98-d829582c6739
workers: Plug some leaks in wproc management code

We let the query handler know that we'll be taking over the socket,
and we free the job-array used for workers. That used to trigger a
double free(), but it appears those days are past.

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

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

When subscribers disconnected, we would earlier leave the ghost
of their subscription behind. This patch makes sure they're removed.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2370 5f96b256-904b-4d8d-8c98-d829582c6739
nerd: Fix host parent path caching

And remove debugging output while we're at it.

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

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

rusage nswap and nsignals are unused on linux (and a lot of other
systems), so we stop sending them for successful checks.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2372 5f96b256-904b-4d8d-8c98-d829582c6739
xdata: Stop lying outrageously about precache savings

It's (sometimes) a little faster to use a precached config, but
reading the (often much) larger config takes a bit of time too,
and the savings are nowhere near as substantial as they once
were.

The largest saving I've seen is around 22%, but that's only for
certain parts of the restart sequence and not all of it, so it's
more like shaving 3-5% off of the total launch time.

However, since it's explicit which parts of config reading are
marked, we round it up to 25% when we give the hint.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2373 5f96b256-904b-4d8d-8c98-d829582c6739
base/config: Stop hinting about the -x option

It's deprecated, so we shouldn't announce it anywhere at all.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2374 5f96b256-904b-4d8d-8c98-d829582c6739
nerd: Fix stupid typo in host_parent_path()

s/ret = malloc(len) + 1/ret = malloc(len + 1)/

And to think I missed that for almost a full day...

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

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

We won't be able to run more than a few less external apps than
ulimit -u, or ulimit -n / 2, so it's good if we know when we'll
hit that limit so we can avoid sending more jobs to our workers
when we do. This patch at least lets us become aware of our own
limites.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2376 5f96b256-904b-4d8d-8c98-d829582c6739
common/macros: Always log warnings from macro resolutions

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2377 5f96b256-904b-4d8d-8c98-d829582c6739
core: Add check_type_name()

Nifty little helper along the lines of state_type_name(), used for
getting 'PASSIVE' or 'ACTIVE' to for example macros.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2378 5f96b256-904b-4d8d-8c98-d829582c6739
common/macros: Stop duplicating memory unnecessarily

Most of the strings we hand back from the macro resolution stuff are
static anyway, so we can get away with this and just free() the
few strings we actually have to generate live.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2379 5f96b256-904b-4d8d-8c98-d829582c6739
core: Stop checking for illegal object names if there can't be any

Previously we used to iterate once over all object names to check
for illegal object char names, even when there weren't any characters
marked as illegal. Return early instead, so we avoid one strlen() and
one full iteration over all characters in the object name.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2380 5f96b256-904b-4d8d-8c98-d829582c6739
macros: (almost) Always strdup() macros when we need to cleanse them

Otherwise we end up in a bad place when sending notifications.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2381 5f96b256-904b-4d8d-8c98-d829582c6739
macros: Remove an essentially unused variable

clean_macro in process_macros_r() is essentially unused as it's always
0 but checked for 1 (which it never can get), so we remove that and
make the code a little easier to follow.

While at it, we remove an unused iterator from clear_contact_macros_r()

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2382 5f96b256-904b-4d8d-8c98-d829582c6739
lib/lnag-utils: Add CHAR_MAP_INIT(k) macro

This is handy when initializing character maps, used to efficiently
locate characters when linearly parsing random data.

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

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