From: Andre Noll Date: Sun, 31 Dec 2017 19:32:52 +0000 (+0100) Subject: Improve daemon_open_log_or_die(). X-Git-Tag: v0.6.2~36 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=a047b764498632d977b75b543165383849a591f0;hp=ec05ce7931f80398c0d628d93c7892d71094d320;ds=sidebyside Improve daemon_open_log_or_die(). If the log file can not be re-opened, the error message is lost because the log file has already been closed when PARA_EMERG_LOG() is called. We can do better by deferring the call to daemon_close_log() until the new log file has been opened. With the patch applied, the reason why the (new) log file could not be opened is logged to the old file. --- diff --git a/daemon.c b/daemon.c index e47639bc..49d2e100 100644 --- a/daemon.c +++ b/daemon.c @@ -234,15 +234,18 @@ void daemon_close_log(void) */ void daemon_open_log_or_die(void) { - daemon_close_log(); + FILE *new_log; + if (!me->logfile_name) return; - me->logfile = fopen(me->logfile_name, "a"); - if (!me->logfile) { + new_log = fopen(me->logfile_name, "a"); + if (!new_log) { PARA_EMERG_LOG("can not open %s: %s\n", me->logfile_name, strerror(errno)); exit(EXIT_FAILURE); } + daemon_close_log(); + me->logfile = new_log; /* equivalent to setlinebuf(), but portable */ setvbuf(me->logfile, NULL, _IOLBF, 0); }