]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Improve daemon_open_log_or_die().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 31 Dec 2017 19:32:52 +0000 (20:32 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 11 Feb 2018 10:28:17 +0000 (11:28 +0100)
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

index e47639bc42864cc4881d5992bb567e902f4752ac..49d2e1007fcf92c99c511fbcadbe0f461a05638d 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -234,15 +234,18 @@ void daemon_close_log(void)
  */
 void daemon_open_log_or_die(void)
 {
  */
 void daemon_open_log_or_die(void)
 {
-       daemon_close_log();
+       FILE *new_log;
+
        if (!me->logfile_name)
                return;
        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);
        }
                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);
 }
        /* equivalent to setlinebuf(), but portable */
        setvbuf(me->logfile, NULL, _IOLBF, 0);
 }