From a047b764498632d977b75b543165383849a591f0 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 31 Dec 2017 20:32:52 +0100 Subject: [PATCH 1/1] 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. --- daemon.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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); } -- 2.39.2