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.
*/
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);
}