core: Consider it a fatal error when we fail to read config

It usually is (although not always). In either case, we won't be
reading all the config and we may not be reading it the way the
user meant us to, so bail out early.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2538 5f96b256-904b-4d8d-8c98-d829582c6739
core: Drop privileges before opening debug log

Otherwise the debug log will (most of the time) be owned by root,
and won't be amended to after the first reload. This means we have
to drop debug logging from the drop_privileges() function, but
since it only ever does anything while we're still in the foreground
that's really not a major issue.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2539 5f96b256-904b-4d8d-8c98-d829582c6739
core: Daemonize before we open any persistent files

Once upon a time there was a keepalive daemon that figured it would
be a mighty fine idea if it closed stdin, stdout and stderr for the
programs it launched. That was kinda stupid, since it caused Nagios
to fail to use its IO broker set. The same sort of thing can happen
with logfiles and other things that uses filedescriptors, of all
kinds, so we avoid opening *any* persistent files before we're done
close()'ing stdin, stdout and stderr.

This means we no longer print the "Finished daemonizing..." message
in the logfile, since it would look pretty stupid there *after* the
"Nagios starting" message (which now prints the correct pid the first
time around, btw).

It also means we never load or initialize modules in any way before
we're done daemonizing, since we'd only have to unload them if we
fail, and they could be subject to the same "oopsie, I killed your
filedescriptor" issue as Nagios core was under such exceptionally
weird and hard-to-debug circumstances.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2540 5f96b256-904b-4d8d-8c98-d829582c6739
buildsystem: Compile nagios.o before linking it

This makes it infinitely more pleasant to run all sorts of static
code analysis tools, which is good, since they sometimes catch
real errors, which are really bad. More often, they catch legacy
code that has become nonsensical by more recent patches and only
serve to confuse developers. Since we coders are so confused as
it is, we might as well avoid more of the same as much as we can.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2541 5f96b256-904b-4d8d-8c98-d829582c6739
core: Fix some clang/sparse warnings

Mostly global-to-static stuff, but also some comparisons of unsigned
variables to subzero values.

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

git-svn-id: https://nagios.svn.sourceforge.net/svnroot/nagios/nagioscore/trunk@2542 5f96b256-904b-4d8d-8c98-d829582c6739
core: Try really hard to log errors regarding logging during reloads

If the user has made a typo in the log_file path and issues a reload,
we didn't print an error message anywhere at all, but silently failed
to log anything at all.

With this patch, we'll redirect such logs to the old logfile, but we
consider it an error that we can't write to the newly configured file
and return an error code promptly.

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

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