Fix display of downtime in notifications.cgi

Fix service downtime notifications being displayed as UNKNOWN and host
downtime notifications being displayed as DOWNTIME but inheriting the
background color of the preceding notification.

This also allows the user to filter for just DOWNTIME notifications and
includes updated CSS for both the Exfoliation theme and the Classic UI.
Export command variable assignments to the environment.

In the POSIX sh language, variable assignments preceding a command are
exported to the enviroment of the command. Previously runcmd_open() was
not handling this for simple commands that don't require a subshell to
run (the shell handles this for more complex commands that we run in a
subshell).

These changes export the variable assignments without requiring a
complete subshell.
runcmd: Handle child errors more thoroughly and uniformly.

runcmd_open() was not detecting some error conditions that would result
in the child runtime environment not being established correctly. With
the exception of close(), calls in the newly created child process that
can fail within reason are now checked and reported to stderr before
exiting.
runcmd: Correct comments and cleanup some code.

Corrected comments regarding 'async-safety', code attribution, and code
function. runcmd_init() is definitely NOT reentrant, and incorrectly
calling this function as if it were would invalidate the reentrancy of
the other functions that access the pids global variable.

Moved Doxygen section end (/** @} */) in runcmd.h inside include guard
in order to not confuse Doxygen. Removed unused and incorrect SIG_ERR
define, and one declaration per line.
runcmd: Improve error handling & memory management.

runcmd_cmd2strv():
Check for valid arguments, test for failed allocation, and
null-terminate the output argv array. Also avoid a potential leak if
returning early on unexpected end of string (really shouldn't ever
happen).

runcmd_open():
Check all arguments are non-null: __attribute__((__nonnull__(1, 2, 3, 5,
6))) is not a guarantee, it is still perfectly possible to pass NULL in
the specified positions and not pass "-Wnonnull" to gcc, or just ignore
the warning if it is generated. Handle failed allocation from
runcmd_cmd2strv(), consider commands with unbalanced quotes an error
(the shell does), and return the correct error code if pipe(pfd) fails.

test-runcmd:
Free our allocated memory. The only unfreed memory is now the pids array
internal to runcmd.c.
Fixed a bug calling killproc_nagios() from stop
Using TERM as suggested in the comment here: https://github.com/NagiosEnterprises/nagioscore/pull/6#discussion_r14309447
Remove unused killproc_nagios() arg, and pass signal name with -s.
Put nagios.configtest in Nagios' var dir.

The file isn't strictly related to the system run state, and it may be
useful to preserve the last configuration errors across reboots.
JSON: Escape backslashes first

This commit causes backslashes to be escaped first so they don't cause
backslashes created by other escapes from being escaped themselves.
Init script: Set variables before sourcing sysconfig.

Doing this after setting the variables allows sysconfig settings to
override the configure/install-time defaults.
Init script: Whitespace and formatting cleanup.
Check events: Don't estimate exec. time in auto-rescheduling.

Estimates of check execution time weren't too sophisticated or uniform
(we only have real measurments for host checks). By removing these
estimates the algirithm is simpler and the new schedule is smoother.

Also use cheduling_info.service_inter_check_delay/4 as a threshold for
determining if check events are too close in time and need to be
rescheduled. This removes hardcoded thresholds and makes the
rescheduling criteria dependent on the acutal configured checks.
Merge branch 'master' of github.com:NagiosEnterprises/nagioscore into emislivec-scheduling
Init script: Don't try to start if already running.

Running start with an instance of nagios already running would result
in the running instance's command pipe being removed. Test that the
lock file does not hold the PID of a running process before attempting
to start a new instance.

Also remove some unused arguments from status_nagios calls.
Init script: Quote kill's signal specification.

This gives a little bit less confusing error message if someone were to
invoke killproc_nagios without specifying a signal to send.
wproc: Correctly calculate remaining time to wait in wproc_reap().
test-runcmd: Fix missing-field-initializers

I'm not quite clear on exactly why I can't get my fedora-gcc to complain
about this, but travis' ubuntu-gcc seems to complain.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
runcmd: Don't crash when exposed to ampersands

An off-by-one error caused us to copy both a null-byte and the job
control character when exposed to commands containing job control
characters. If there are more than 10 of those, we'd run out of memory
and write to uninitialized memory. If we were unlucky, the uninitialized
memory was "badly" located, which means worker crash and bug op5#8182.

The fun thing is, the way the "embedded shell" thingie works, every time
you call add_ret(), you might as well just return - alas, we don't, for
reasons that are hard to see clearly but I assume involve having
something to speed up in a future version. Oh well.

So, back to the bug: we discovered a case where knew we would never,
ever read the output, and proceeded to handle that by... Writing too
much to the output to the point where the worker crashed.

Proving, with a test, that we didn't really do anything is hard. The
extra test case added to test-runcmd doesn't fail or generate a crash
with the old code, but at least it generates memory errors when run
through valgrind, and those errors are now gone.

So, this should fix the crash in bug op5#8182, when using the initial,
incorrect quoting - obviously, the check result still won't make sense
as it's wrong, but now you get to see that rather than infinite crashes.

Change-Id: I0b7ebd9a782125bc060ea9eb785d70de7bb69228
Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Merge branch 'master' of github.com:NagiosEnterprises/nagioscore into emislivec-tracker0582-runcmd