Open journal before daemonizing, so we can fail in foreground

Just like we open server.log.  Also permits calling journal_prng()
right where we seed the PRNG.
This commit is contained in:
Markus Armbruster 2012-08-04 20:15:15 +02:00
parent fc64b4fa83
commit efc3a8e6e2
2 changed files with 8 additions and 7 deletions

View file

@ -27,7 +27,7 @@
* journal.c: Log a journal of events to a file * journal.c: Log a journal of events to a file
* *
* Known contributors to this file: * Known contributors to this file:
* Markus Armbruster, 2004-2011 * Markus Armbruster, 2004-2012
* Ron Koenderink, 2008 * Ron Koenderink, 2008
*/ */
@ -82,12 +82,14 @@ static void
journal_entry_vstart(char *fmt, va_list ap) journal_entry_vstart(char *fmt, va_list ap)
{ {
time_t now; time_t now;
empth_t *self;
if (!journal) if (!journal)
return; return;
time(&now); time(&now);
self = empth_self();
fprintf(journal, "%.24s %10.10s ", fprintf(journal, "%.24s %10.10s ",
ctime(&now), empth_name(empth_self())); ctime(&now), self ? empth_name(self) : "Main");
vfprintf(journal, fmt, ap); vfprintf(journal, fmt, ap);
} }

View file

@ -31,7 +31,7 @@
* Steve McClure, 1996, 1998 * Steve McClure, 1996, 1998
* Doug Hay, 1998 * Doug Hay, 1998
* Ron Koenderink, 2004-2009 * Ron Koenderink, 2004-2009
* Markus Armbruster, 2005-2011 * Markus Armbruster, 2005-2012
*/ */
#include <config.h> #include <config.h>
@ -286,7 +286,6 @@ main(int argc, char **argv)
} }
#endif /* !_WIN32 */ #endif /* !_WIN32 */
start_server(flags); start_server(flags);
journal_prng(seed);
for (;;) { for (;;) {
sig = empth_wait_for_signal(); sig = empth_wait_for_signal();
@ -359,6 +358,9 @@ init_server(unsigned seed, int force_bad_state)
io_init(); io_init();
init_nreport(); init_nreport();
if (journal_startup() < 0)
exit(1);
journal_prng(seed);
loginit("server"); loginit("server");
} }
@ -377,9 +379,6 @@ start_server(int flags)
empth_init((void **)&player, flags); empth_init((void **)&player, flags);
if (journal_startup() < 0)
exit(1);
update_lock = empth_rwlock_create("Update"); update_lock = empth_rwlock_create("Update");
shutdown_lock = empth_rwlock_create("Shutdown"); shutdown_lock = empth_rwlock_create("Shutdown");
if (!update_lock || !shutdown_lock) if (!update_lock || !shutdown_lock)