logging: exit process in case logfile is not writable.
authorMarko Kreen <markokr@gmail.com>
Tue, 31 Aug 2010 08:32:42 +0000 (11:32 +0300)
committerMarko Kreen <markokr@gmail.com>
Tue, 31 Aug 2010 08:52:43 +0000 (11:52 +0300)
Otherwise configuration mistakes can be hard to diagnose.

usual/logging.c

index db53e3b748fcafc8391a050ac56640cef866453b..b77a62b1e0360065c83e0838219ed4e7dd06bc4a 100644 (file)
@@ -116,18 +116,18 @@ void log_generic(enum LogLevel level, void *ctx, const char *fmt, ...)
 
        format_time_ms(0, timebuf, sizeof(timebuf));
 
-       if (!log_file && cf_logfile) {
-               static int error_reported = 0;
-
-               if ((log_file = fopen(cf_logfile, "a")) != NULL) {
+       if (!log_file && cf_logfile && cf_logfile[0]) {
+               log_file = fopen(cf_logfile, "a");
+               if (log_file) {
                        /* Got the file, disable buffering */
                        setvbuf(log_file, NULL, _IONBF, 0);
-               } else if (!cf_quiet && !error_reported) {
-                       /* Unable to open, complain once */
-                       fprintf(stderr, "%s %u %s %s: %s\n", timebuf, pid,
-                               log_level_list[2].tag, cf_logfile,
+               } else {
+                       /* Unable to open, complain and fail */
+                       fprintf(stderr, "%s %u %s Cannot open logfile: '%s': %s\n",
+                               timebuf, pid, log_level_list[0].tag,
+                               cf_logfile,
                                strerror_r(errno, ebuf, sizeof(ebuf)));
-                       error_reported = 1;
+                       exit(1);
                }
        }