core: Only mark successfully started checks as running

Previously we used to mark checks as running as soon as we tried to
launch them, no matter if we failed to send them to a worker or not.

With this patch, we're a lot more careful and only mark them as
running and update the statistics when we've managed to successfully
paw them off to one of our workers.

Original-patch-most-likely-by: Ton Voon <ton.voon@opsview.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Plug a leak on SIGHUP and RESTART_PROCESS commands

The hash table for specialized workers was previously leaked upon
soft reloads. This patch corrects it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Reset some internal book-keeping variables when we launch

This has no functional impact, but makes log-messages from the
bootstrap procedure look sane even if they come during a soft reload
rather than a full restart.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Fix some comments so they're politically sane

Using people's initials and company names in comments is just plain
dumb. If I leave stuff like that in I'm sure pretty soon the marketing
people at $dayjob will ask me to sprinkle "op5" wherever I've touched
the code, and I'd be at it for days if I had to do that.

While I'm appalled at making code changes for political reasons, I'm
frankly disgusted by the thought of having to obey people who consider
search engine optimization their number one priority.

Besides, it makes sense to remove stamps of ownership like these,
since we don't want people who want to write patches to go asking the
original authors for permission to change the code they've already
let hang.

Signed-off-by: Andreas Ericsson <ae@op5.se>
lib/worker: Fix think/typo in loggin condition

Since we read() in a loop and we tag the filedescriptors with
O_NONBLOCK, we more or less expect to end up at the EAGAIN
state every time we reap a check that times out, gets killed
and gets reaped by the SIGCHLD reaper.

This patch just alters the conditions slightly so we never
log EAGAIN warnings from reading, or any errors from the final
read, instead of just dropping EAGAIN warnings from the final
read.

Signed-off-by: Andreas Ericsson <ae@op5.se>
t-tap: Drop test_strtoul()

It's a godsdamn ansi C function, so it's not going to differ in
behaviour between systems. If there *are* systems where strtoul()
or other ansi C functions don't behave according to standard, we
most certainly don't support them.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Make core tap-tests pass once again

The original tests were written for Nagios 3. Most of them no longer
even compile, but they do produce an ungodly amount of warnings and
errors when one tries to.

We leave the obsoleted code in place, along with their buildrules,
in case someone wants to take a stab at fixing them, or at least as
a sort of map to what needs testing.

The important part is that 'make test' now works properly and can
be incorporated into automated buildsystems.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Propagate service values to hosts at configure time

This makes it possible to calculate a network outage value by simply
looking at the hosts, and the services will always be considered the
primary "value-bringers" in any configuration.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Start getting rid of the xdata directory

The xdata directory has long since outlived its usefulness. It was an
experiment once, but has since years and years back become a permanent
fixture, and we won't be creating new ways to parse configuration or
stash status data anytime soon (unless we build in ways for modules to
take over core functionality, at least).

Step one is to remove the plethora of places where we read config and
merge those variables into the main config file reading routine, which
this patch at least makes a start at.

Signed-off-by: Andreas Ericsson <ae@op5.se>
core: Stop double-logging SIGHUP's

Previously we would log them twice. Once from the sighandler, stating
that we were going to shut down, and once from the main loop, stating
that we would restart. Often, they would follow each other immediately,
which was sort of confusing. With this patch, we only log the shutdown
thing if we actually are shutting down.

Signed-off-by: Andreas Ericsson <ae@op5.se>
t-tap/test_timeperiods: Silence a bunch of warnings

Mainly "no return in non-void function" and "unused variable foo"
stuff. This makes running tests a lot less fugly, so perhaps people
will actually do it.

Signed-off-by: Andreas Ericsson <ae@op5.se>
cgi's: Refactor the whole config + status data reading somewhat

Most cgi's read everything in exactly the same way, but link to
different header and footer functions. By passing the header and
footer as arguments to the newly created cgi_init() function, we
can bypass that particular hurdle and unify how most the cgi's
process configuration and status data.

The ones we can't convert are the ones that sometimes generate images
and the mobile ones, but it's still a pretty neat win in code-size
reduction.

Signed-off-by: Andreas Ericsson <ae@op5.se>
cgis: Pass main config file to status data reading routines

It makes absolutely no sense what so ever to pass in the cgi.cfg file
location, as the xdata/xsddefault.c routines had to parse out the main
config file first and then parse that file to get the status_log
location. Since the cgi's always (without fail) know where the main
config file is by the time we read the status data, we might as well
pass the main config file directly and get rid of some 50 lines of
cumbersome code that just made it completely impossible to unify config
parsing in any way.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Remove #ifdef USE_X* conditionals

Since we'll be keeping the current xdata routines until something
better comes along, when we'll simply make a clean switch, we can
reduce our LoC-count quite simply by removing the #ifdef USE_X*
preprocessor conditions in the code, thus taking preparations one
step further towards getting rid of the xdata directory altogether.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Stop parsing config from xdata/xsddefault.c

We can easily make status_file a global variable instead and let it
be parsed from base/config.c and cgi/cgiutils.c. This patch lets us
drop quite a lot of almost-duplicated code, which is a Good Thing(tm).

It also takes us one step further in the war on the xdata directory.

Signed-off-by: Andreas Ericsson <ae@op5.se>
perfdata: Run host and service perfdata commands through workers

This means we parallelize the perfdata updating commands, so we no
longer stop doing *everything* just to run a command that ships off
perfdata somewhere.

Unfortunately, we can't do the same with the perfdata file processing
commands, since those generally move the file out of the way and we
have to re-open the file after they have successfully completed.

Writing to a temporary (but named) spoolfile which we later move to the
"real" perfdata file before we run the command would allow us to issue
a simple "rename()" call and then send the processing command to one of
our workers, but that's a larger patch, and the code works as-is so
I'm reluctant to fiddle with it more than necessary.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Janitor patch cgis: Silence a bunch of compiler warnings

Primarily shadowed variables, but some unused and some comparisons
between signed and unsigned etc as well.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Stop making xdata/ stuff almost-but-not-really configurable

Removing it means we can get rid of quite a lot of Makefile code,
as well as a ton of ./configure lines and the sometimes confusing
comments at the end of a ./configure run where we tell the user
that they've "chosen" some particular way of doing things.

While at it, we dig through the xdata/ files and simplify them
somewhat in order to prep them for the upcoming code-migration.
Worthwhile, since one can plainly see that comments, downtime and
perfdata code can just be moved without even changing buildrules.
Reflective changes of that insight are carried over to the cgi
Makefile, where the xcomment-cgi.o and xdowntime-cgi.o targets
are removed completely, as they weren't linked into aything
before anyway.

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