core: Fix logfile permissions, attila style

In the case where we're started as root, there are issues in the
configuration and we have no logfile, such as when a user first
installs Nagios and fires it up via the init-script through a
reboot, we will fail to open the logfile after having dropped
root privilegs.

With this patch, we chown the logfile and debug logfile to the
destination user just before we call setgid() and setuid(),
which is the hardcore way of making sure we can always write
to our logfile.

In the case where we're running as a non-root user, the call
is never made and we rely on the check to see if we can open
the logfile after privileges are dropped for proper logging.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2618 5f96b256-904b-4d8d-8c98-d829582c6739
base/nagios: Stop truncating nagios.log when doing sanity checks

That means we aren't allowed to try to open the logfiles with
"w" when checking if we *can* open it, since that truncates the
file.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2619 5f96b256-904b-4d8d-8c98-d829582c6739
downtime: Fix crash when using distributable downtime commands

The function that implements the distributable downtime commands kept a
pointer to the next downtime, which is a rubbish idea when the
unschedule_downtime deletes any triggered_by downtimes, and scheduled
downtimes triggered by this one typically start at the first element
right after this one.

To get nagios to crash using the old code, get a configuration with a
few hosts, make all of them depend on one single host, schedule and
propagate a triggered host downtime on the parent, and then unschedule
the downtime on the parent using, for example,
DEL_DOWNTIME_BY_HOST_NAME.

This prevents the crash by first locating any matching downtimes and
copying the information about the downtime type and id to a separate
downtime list, and only then try to unschedule anything. This might lead
to unschedule_downtime having to look for downtimes that no longer
exist, which is slow, but it should only really happen for
DEL_DOWNTIME_BY_START_TIME_COMMENT. I can see no easy way around this
without breaking API and/or ABI.

Signed-off-by: Robin Sonefors <robin.sonefors@op5.com>
Signed-off-by: Andreas Ericsson <ae@op5.se>

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