Fix database failure reporting before the config file is first read.
authorMichael Poole <mdpoole@troilus.org>
Mon, 21 Sep 2009 00:45:08 +0000 (20:45 -0400)
committerMichael Poole <mdpoole@troilus.org>
Mon, 21 Sep 2009 00:45:08 +0000 (20:45 -0400)
src/recdb.c (explain_failure): When MAIN_LOG is NULL, report to stderr.

src/recdb.c

index 262de7fb39ba37777a8ba6183a0a75bf333b0027..8f4e8c567e7c756cdbca27ed2f2125d75e8e1760 100644 (file)
@@ -568,9 +568,16 @@ failure_reason(int code)
 void
 explain_failure(RECDB *recdb, int code)
 {
-    log_module(MAIN_LOG, LOG_ERROR, "%s (got '%c') at %s line %d column %d.",
-               failure_reason(code), code & 255,
-               recdb->source, recdb->ctx.line, recdb->ctx.col);
+    static char msg[1024];
+    snprintf(msg, sizeof(msg), "%s (got '%c') at %s line %d column %d.",
+             failure_reason(code), code & 255,
+             recdb->source, recdb->ctx.line, recdb->ctx.col);
+    if (MAIN_LOG == NULL) {
+        fputs(msg, stderr);
+        fputc('\n', stderr);
+        fflush(stderr);
+    } else
+        log_module(MAIN_LOG, LOG_ERROR, "%s", msg);
 }
 
 const char *