utils: Add uninterrupted_write()

This function lets us transparently handle EAGAIN/EINTR during writes
by retrying, which we want to do any time they pop up. This also has the
added benefit of silencing warnings about unchecked returns for write
calls, in addition to actually checking the return and logging a message
if something goes horribly wrong, which should make debugging easier in
the future.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
shared: Fix null pointer deref in my_strtok

If my_strtok was supplied with a NULL buffer on the first call,
it would (needlessly) trigger a null pointer dereference. This patch
adds a check for that case and a test case that triggers the error
without the patch applied.

Signed-off-by: Anton Lofgren <alofgren@op5.com>
updated gplv2

in order to fix the rpmlint "incorrect-fsf-address" issue

Signed-off-by: Sven Nierlein <Sven.Nierlein@consol.de>
removed orphanded files

since we do not longer ship cgis, we don't require test cgi.cfgs anymore.

Signed-off-by: Sven Nierlein <sven@nierlein.de>
Merge pull request #78 from catharsis/strtok-null-pointer-deref

shared: Fix null pointer deref in my_strtok
Merge pull request #76 from catharsis/handle-write-intrs

utils: Add uninterrupted_write()
shadownaemon: make sure command files are cleaned

sometimes command files are not removed properly. Delete
them after they should have been processed to avoid processing
them over and over.
shadownaemon: close sockets when connect fails

this closes a ressource leak on unavailable remote sites.
shadownaemon: fixed endless loop

when full refreshing data it could happen that the shadownaemon gets stuck in an endless
loop when it trys to skip already syncronized comments or downtimes.
This patch makes sure we iterate over all all comments, even if some are skipped.

Signed-off-by: Sven Nierlein <Sven.Nierlein@consol.de>
Trust our object pointers

If we fail to parse configuration properly, we need to know that
by getting a coredump, not by ignoring to send out a notification
or some other stupid crap, so checking if assignment turned out
well just has to go. It's a legacy from when we used to do
object lookups based on names anyway.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Use current host state as route_result

Once upon a time we used to run route checks (ie, a check of a host
and its parents) synchronously, and back then we actually set the
route_result variable to something sensible at the end of a failed
service check. However, with The Big Performance Rewrite, route
checks are now asynchronous, so we'll never get a proper result
from it in time to determine if the host is down or not before
we move on to notifying about the service.

A 100% correct solution would be to add triggered notifications,
where one notification can't be sent unless we know the absolute
root cause of the problem (or at least some time has passed since
the problem was detected), but with this fix we just use the current
host state as the route result, meaning we'll never send any
service notifications for hosts that are DOWN or UNREACHABLE
provided:
a) The host check is executed after the host has gone down but
   before the service check is executed
b) The triggered host check comes back with a correct result
   before the service's max_check_attempts has been reached.

Ignoring pathological cases where the host is basically flapping
up and down, this solution will be Good Enough(tm) and took all
of 30 seconds to write.

Signed-off-by: Andreas Ericsson <ae@op5.se>
.gitignore t-tap/test_commands

Buildproduct, so it shouldn't pretend it wants to be tracked.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Get rid of check delay/spread

Everything about it is just absolutely, ridonculously daft - just run
the bloody checks normally, and stop dicking about with whatever that
was!

The most hilarious thing about it is that it *does* have the correct
code - too - except only as a fallback, in case the insane code ended up
with a crazy value.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Update test config to not use deprecated parameters anymore

Getting a bunch of warnings when reading configuration is not so
very nice.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Make timeperiod timeranges end when they say they do

Previously we would include the end-minute-mark for the timerange
as being a "valid" time, which it really isn't. A timerange
specified as "00:00:24:00" doesn't last the first minute of the next
day. It ends (and starts) at midnight. In the same way, 00:00-00:15
includes all the seconds from midnight up to 00:14:59, but not the
00:15:00 second (or anyone thereafter).

This patch makes it so, and also updates relevant tests to reflect
the change.

Signed-off-by: Andreas Ericsson <ae@op5.se>
timeperiod tests: Make 24x7 tests sort-of-optional

When debugging or refactoring the timeperiod code, it's pretty damn
annoying to have almost 6000 tests that clutter up the screen with
their output. Adding printf() debugging makes the whole mess
completely unbearable. With this patch, it's straightforward to
skip those tests, although that will result in a tap warning about
us not running the number of tests we planned.

While at it; fix the loops. Unconditionally incrementing a counter
inside a while()-loop and unconditionally initializing it just
before it is just bad style.

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

Unfortunately, a lot of the more complex timeperiod tests were
downright wrong, leading us to use buggy code in the timeperiod
handling.

This patch fixes them. Future commits will fix the broken tests
in a series of patches reworking them completely.

Manually going through the ~400 relevant testcases was *not* fun,
so please be really careful when adding more tests and make sure
the expected output is actually correct.

Signed-off-by: Andreas Ericsson <ae@op5.se>
test-config: Add more timeperiods for testing

Signed-off-by: Andreas Ericsson <ae@op5.se>
test_timeperiods: Revamp and fix timeperiod testing

Earlier timeperiod tests tested only the high level functions
and had very little debug output for when things went wrong.

With this patch, we add some convenient macros that explain what
we got and what we expected.

We also add tests for get_matching_timerange, which is at the
heart of all other timeperiod stuff.

Since a lot of tests failed, I've also gone through all of them
to make sure all tests are actually sane, and the ones that were
previously broken have been fixed so the input actually matches
the expected output.

Since there are a *lot* of tests, I've only updated the broken
ones to use the new macros, since I needed the debug output from
them while fixing them.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Add macro for calculating next check time

The signature is next_check_time(o), where o is either a host or a
service. It yields the next check time (surprise!) by choosing the
correct interval based on the state of the object and the last_check
variable of the object, so those two have to be set.

The interesting part about this is that we can now get scheduling
retention exceptionally cheaply, by simply using the next_check logic
we can (and should; Patch to follow) the whole swamp of fiddling
with checks that are already scheduled but have had their intervals
changed since restart when initially scheduling checks.

Assuming we take into account the fact that checks can be scheduled
to run in the past if they were supposed to run while we were shut
down, we now have an excellent oneline tool to handle scheduling
data retention with zero-exception code.

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