lib/runcmd: Use _exit() instead of exit() when execvp() fails

Otherwise we'll run all atexit() handlers, which means profiling
worker processes when plugins are missing will cause the forked()
copy of the worker process try to merge profiling info with that
of earlier (failed) command executions. Since they lock the file
when merging and merging is non-trivial, that means we quickly
run out of available filedescriptors and end up in a severely
bad place, where checks are no longer run.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2329 5f96b256-904b-4d8d-8c98-d829582c6739
lib/runcmd: Print plugin name when we fail to execvp()

This makes debugging things quite a bit easier.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2330 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Avoid issuing 'kill(0, SIGKILL)'

It appears we can sometime get child processes with pid 0 when
checking if any worker jobs have timed out. That's pretty bad and
it's still not known why it happens, but when it does we must take
care not to issue kill(0, SIGKILL), since that kills the worker
and all its running jobs, finally leaving Nagios with no workers
and unable to do anything.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2331 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Stop checking for timeouts when we have no running jobs

It appears that testing with small configs is important too.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2332 5f96b256-904b-4d8d-8c98-d829582c6739
lib/nsock: Make doxygen comments work properly

We were lacking the file header and had a rogue macro comment
earlier.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2333 5f96b256-904b-4d8d-8c98-d829582c6739
contrib/.gitignore some more build products

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2334 5f96b256-904b-4d8d-8c98-d829582c6739
Add lib/nspath, the nagios path handling library

It's still pretty small but will suffice for our needs. The idea is
to easily and efficiently be able to resolve relative paths into
absolute ones, to better support moving ones installation around
in the filesystem (and, as an extension, make it easier for me to
run tests against other peoples configurations).

I haven't spent hours of effort to make this the most efficient
code in the world, since it will only be used when parsing the main
configuration, but it doesn't have to be and it seems plenty fast
enough for our purposes.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2335 5f96b256-904b-4d8d-8c98-d829582c6739
core: Allow relative paths for everything in nagios.cfg

Previously it was supported for object cfg_file and cfg_dir
directives, but that was inconsistent and surprising, since there
are lots of paths in nagios.cfg that can benefit from being relative
to the directory the config file resides in.

With this patch all paths in nagios.cfg are relative to the directory
where nagios.cfg resides (assuming I didn't miss any, ofcourse).

This makes it positively trivial to setup a test config, create
the directory structure for it and then send the entire thing to
a remote system for deployment or testing, without having to have
the exact same directory structure for everything.

While at it, we fix some broken indentation (in code we touched
upon anyway) and make check_result_path and temp_path two distinctly
different options, as opposed to earlier when check_result_path
would overwrite temp_path if check_result_path was specified last.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2336 5f96b256-904b-4d8d-8c98-d829582c6739
core: Make subsystems log with a unique tag

Since we now have subsystems (nerd and query-handler), it's kind of
important that we're able to find their logmessages quickly when
debugging, or that we can ignore them easily when machine-parsing
the logfiles. This patch makes queryhandler and nerd log messages
with 'qh: ' and 'nerd: ' prefixes, respectively, making it relatively
trivial to filter in or out their messages from the log.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2337 5f96b256-904b-4d8d-8c98-d829582c6739
core: Add timing points all the way up to the execution loop

This is necessary to (easily) measure where we spend a lot of time
while restarting, since config parsing is only a part of it. By
tracking it all the way until we enter the event execution loop
we effectively track all the time we use for anything at all
up until the point where we may be able to start running checks.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2338 5f96b256-904b-4d8d-8c98-d829582c6739
core: Give Nagios the ability to act as an on-demand worker for itself

With on-demand workers, one can easily tweak the number of configured
workers and run tests with general-purpose workers without having
access to special software.

This also makes it possible to launch workers efficiently while not
worrying about memory leaks from modules and whatnot.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2339 5f96b256-904b-4d8d-8c98-d829582c6739
core workers: Stop being so noisy when workers are trying to register

There is such a thing as a documentation for worker processes after
all, and developers who write workers are likely to read it, so we
needn't bother with having the query format inline in the code.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2340 5f96b256-904b-4d8d-8c98-d829582c6739
core: Register @wproc query handler before launching workers

This makes it possible for workers to start shipping commands to
Nagios directly if they so wish, which is nifty for when we want
to support keepalive and configured bootstrapping of external
workers.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2341 5f96b256-904b-4d8d-8c98-d829582c6739
core: Grok 'pid=<pid>' when external workers connect

This makes it possible to run the "workers_alive()" thing for
local workers that call in to do work.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2342 5f96b256-904b-4d8d-8c98-d829582c6739
core: Use "wproc" prefix when logging worker stuff

This makes it easy to grep for such issues.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2343 5f96b256-904b-4d8d-8c98-d829582c6739
lib/worker: Add spawn_helper()

This one just kicks off any random helper program with the passed
arguments. It's nifty if we want to spawn external workers from
other sources than us.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2344 5f96b256-904b-4d8d-8c98-d829582c6739
core: Set MACRO_OBJECTCACHEFILE from base/config.c

This lets us remove one round of reading the main config file from
the xdata stuff completely.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2345 5f96b256-904b-4d8d-8c98-d829582c6739
xdata: Remove two useless #ifdef NSCORE

They're already inside conditions of the exact same type, so there's
no need to issue it again and make the code any harder to read.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2346 5f96b256-904b-4d8d-8c98-d829582c6739
core: Stash path to nagios binary

This makes it easy to use the core binary for other purposes than
to run a scheduler, which is quite nifty since we know our own
binary is always present.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2347 5f96b256-904b-4d8d-8c98-d829582c6739
core: Launch workers by fork()+execv()

This solves the previously unsolvable problem of eventbroker modules
that allocate memory before our workers come alive, making our
workers huge compared to what we want them to be.

Before this patch, using 2954 hosts and 24850 services with Merlin
and livestatus loaded, workers use about 32mb resident memory, with
1.1mb shared.
With this patch, workers are down to about 2.1mb, with 720kb shared.

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

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