Avoid dereferencing NULL, at all costs

This is probably the fugliest commit I've ever made, but apparently
it has to be done to avoid crashing horribly on configs with no
servicegroups, hostgroups, services, escalations, dependencies or
contactgroups.

Since sed did it, we get host and service null-ness safety for
free. Yay...

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2288 5f96b256-904b-4d8d-8c98-d829582c6739
Undo the null dereference list-to-pointer-array craziness

Coding while drunk is apparently not always such a stellar idea.

Instead, we add *_ary pointer-to-pointer arrays for all objects
so we have some means of getting hold of the objects that lack
'next' pointers (which will be all of them in Nagios 5).

This makes porting modules from Nagios 4 to Nagios 5 a lot more
pleasant, avoids the null pointer dereference and removes the
hugely ugly and unwieldy ternary statements that protected us
against coredumps caused by some object type not being present.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2289 5f96b256-904b-4d8d-8c98-d829582c6739
Force-install headers in $includedir/nagios

This way our addon projects know to always #include <nagios/foo.h>,
which makes perfect sense and means addons can have headers sharing
names with those of Nagios without causing conflicts or confusion.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2290 5f96b256-904b-4d8d-8c98-d829582c6739
Fix typo: s/hostescalation_list/hostescalation_ary/

This avoids a coredump when freeing memory for a configuration
that has hostescalations.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2291 5f96b256-904b-4d8d-8c98-d829582c6739
core: Resolve contacts and contactgroups for services

Livestatus crashes pretty hard when it gets service requests
without this patch.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2292 5f96b256-904b-4d8d-8c98-d829582c6739
Stop verifying contacts and contactgroups twice

Since we already do it once when we register the objects, we might
as well set the group_ptr there and avoid iterating over all contact
and contactgroup members everywhere else.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2293 5f96b256-904b-4d8d-8c98-d829582c6739
Add 'dist' make target

We first create a symlink to ourselves and then create a tarball
excluding nested symlinks of ourselves. This way we can create a
tarball without leaving the current directoy.

Signed-off-by: Sven Nierlein <sven@nierlein.de>
Patched-by: Sven Nierlein <sven@nierlein.de>
Signed-off-by: Andreas Ericsson <ae@op5.se>

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

It only calls out to run_scheduled_host_check() anyway, so the only
real change is to call that function instead from the only callsite
perform_scheduled_host_check() had.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2295 5f96b256-904b-4d8d-8c98-d829582c6739
Make online_cpus() return at least 1

This makes calculations a bit easier when we need to autodetermine
something where knowing how many cores we have online is relevant.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2296 5f96b256-904b-4d8d-8c98-d829582c6739
core: Create more workers when asked to auto-decide

Two workers didn't work quite so well with large installs, but
the previous hardcoded value of 4 seems to have been quite ok
for most setups, so we're going with that as a minimum thing
and set no upper cap, as workers will mostly sleep anyways.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2297 5f96b256-904b-4d8d-8c98-d829582c6739
nagios.c: Take typical config file location from DEFAULT_CONFIG_FILE

This way it gets automagically updated whrn running ./configure

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

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

Setting 'present' as the end date for the copyright makes sense so
long as we change it when the copyright owners change.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2301 5f96b256-904b-4d8d-8c98-d829582c6739
nagios.c: Mark -x as a deprecated option and remove -o altogether

-o used to be commented out, and -x used to be flagged as potentiall
dangerous with the "USE WITH CAUTION" text, so this just brings help
texts back in line with what we actually implement.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2302 5f96b256-904b-4d8d-8c98-d829582c6739
Make update checks work again

Carry-over from op5 specific code. Bleh...

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

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

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2304 5f96b256-904b-4d8d-8c98-d829582c6739
worker: Make it easier to use from 3rd party code

We split the child_process struct into two parts - one public half that
anyone implementing a worker will probably care about, and one private
one that adds statistics for nagios to use.

We add a simple callback arg to enter_worker, and make it public, so we
can override the callback in 3rd party code and make it do other stuff
with jobs than simply to spawn commands.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2305 5f96b256-904b-4d8d-8c98-d829582c6739
base/commands: Add source_name to command worker

source_name is a fairly recent addition, but it makes it possible to
display very useful names, assuming it's set everywhere. So set it.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2306 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Wrap worker variables into a struct

This creates the possibility to have more than one list of workers, each
having their own length and load distribution.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2307 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Use source_name to print which worker logged something

It looks nicer for the regular workers, and makes more sense for
non-standard workers.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2308 5f96b256-904b-4d8d-8c98-d829582c6739
base/workers: Make it possible to register workers through query_handler

If a process opens the query handler socket, and sends a string on the
form
	@register_worker name=<name> plugin=<plugin1> plugin=<pluginN>
this process will be considered the only worker authorized for all the
plugins listed in the string.

It is possible for two processes to register for the same plugin, then
the load from the checks will be distributed between them evenly.

If the worker process dies, nagios will start to distribute the load
between the remaining workers for that plugin. If all of them dies,
nagios will move them back to the internal workers. Nagios will not
reschedule the already sent-out jobs, yet, though.

This creates the possibility to create workers that work completely
fork-free, which is sometimes a big win: embedded perl (or embedded
python/ruby/whatever) could be brought back through this API, rather
than through the old ifdef-heavy, in-core way. SNMP checks are another
example of checks that could benefit greatly from a dedicated worker.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>

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