Commit f0b822a8 authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

Log: Fix error handling of debug file open

Logging is not yet initialized, we have to use fprintf() here.

Thanks to Pavel Tvrdik for noticing and debugging it.
parent f1f39bb9
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdarg.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>

#include "nest/bird.h"
#include "nest/cli.h"
@@ -314,7 +315,11 @@ log_init_debug(char *f)
  else if (!*f)
    dbgf = stderr;
  else if (!(dbgf = fopen(f, "a")))
    log(L_ERR "Error opening debug file `%s': %m", f);
  {
    /* Cannot use die() nor log() here, logging is not yet initialized */
    fprintf(stderr, "bird: Unable to open debug file %s: %s\n", f, strerror(errno));
    exit(1);
  }
  if (dbgf)
    setvbuf(dbgf, NULL, _IONBF, 0);
}