checks: Consider long output when stalking

This patch fixes a bug where Nagios would not consider if the long
plugin output had changed when deciding on whether to generate an alert
for hosts and services for which stalking was enabled.

To achieve this, the API for process_host_check_result has changed in a
non-backwards-compatible way, by means of no longer exposing it since it
never should have been exposed to begin with (it's a very internal
helper function).

The patch includes test cases to reproduce the bug in the
test_neb_callbacks suite, since those already had some tests dealing
with stalking in particular.

This fixes op5#8102.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
downtime: Don't crash when host downtime_depth < 0

When a host's downtime_depth was going to go below zero, instead of
ignoring it like a good little monitoring system (not one that's as good
as one that would actually log it, but still), Naemon would dereference
svc (which pointed to NULL) and then try decrement a value only a couple
of dozen bytes into the memory address space, still firmly inside kernel
space, leading to instant crashes and sadness all around.

Bad Naemon! You're not supposed to look at kernel space memory! Now go
look at the downtime type before doing anything else!

Yes, just like that! Who's a good boy? You're a good boy! Now you've
resolved bug op5#8440!

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
checks: Add broker attribute for first check

Merlin insists on not using a check's initial state, but instead assumes
that every user of the merlin log database pretends that there's a state
called "pending" that all checks are in until their first check run -
despite the fact that Naemon actually has a state for them, configurable
via the initial_state variable. Therefore, it needs Naemon to tell it
that "This is the first check result in the history of everything", so
it can log it to database, so the pending will end already.

This adds that hook for merlin, so merlin patches can fix bug op5#8798.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
notifications: Increment counter after _START hook

The current_notification_number is supposed to be increased when, and
only when, an notification is sent - that is, it is initially
incremented, but if there was nobody to notify, it is decremented back
again.

There are two global neb hooks per notification - one at _START and one
at _END. You might think that _START runs before, and _END runs after.
You'd be wrong then, though: _START runs after
current_notification_number has been incremented, and if it cancels the
notification, current_notification_number will - incorrectly - stay
incremented.

The result, for merlin, is that it will end up distributing blocked
notifications, so that the current notification number will grow on
other nodes, but stay at whatever it is at on the current node.

This makes _START run at the start.

Change-Id: I50701a929201a040ac572f7be98cec6f2c7f60ae
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
signals: POSIX compliance & cleanup

This patch introduces some amount of sanity to the way we treat signals.
In particular, we no longer call non-async-signal-safe functions from
our (main) signal handler, instead opting for recording the received
signal, and its desired action, in volatile storage. This avoids
triggering undefined behaviour, which is a good thing.

I also replaced the array-of-arbitrary-signal-macro-names strsignal,
which handles edge cases such as signum < 0 and the like by itself.

This also fixes (among other races) the occurrence of doubly logged signal
reception messages, such as:

"
Caught SIGTERM, shutting down...
Caught SIGTERM, shutting down...
"

which is just ugly.

It also simplifies the program flow, which is a Good Thing and Terribly
Necessary.

Other things done in this patch:
* remove ifdef for RLIMIT_CORE and drop SEGV signal handler registration
This is just silly.

* don't "handle" sigxfsz inside the signal handler
This is just undefined behaviour and race conditions

* volatile sig_atomic_t for signal flags
Which is the only thing you're allowed to write to without entering
undefined behaviour-land

* be explicit about which signals trigger what action, ignore everything
else
Because explicit is better than implicit and that is the doggone truth

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
configure.ac: Quote macro definitions

Make install should be able to override the prefix - when it does, it
should chain upwards through the macro hierarchy to our custom paths.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
configure: Add separate option for naemon config dir

This way, by default, naemon config ends up in /usr/local/etc/naemon/ (or
/etc/naemon/, with a distribution prefix), instead of /usr/local/etc (or
/etc). In other words, it's what you'd expect, without any additional
flags - and if you opt to change it, the init dir is no longer defined
as existing inside the configuration dir, so you won't have to discover
and fix that little gotcha.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
build: fix for compilers with without -Wno-unused-result

Naemon and its lib - and thus also its misplaced lib tests - are built
with -Werror, and if the compiler doesn't like -Wno-unused-result, the
unused results will cause compilation errors.

Fix this by testing the results, as that could in fact prevent bugs.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Remove global PROGRAM_VERSION symbol

autoconf (or is it automake?) provides us with a VERSION symbol which
does the same thing, so we don't need it.

If we do want the version in a module, we can still use
get_program_version to get it - though unlike the PROGRAM_VERSION
definition, this won't return the version of naemon that the module was
built against, but instead the version it's running against. Which is
probably going to be more useful, anyway.

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