diff --git a/cmdline/snapraid.c b/cmdline/snapraid.c index be45fa7b..0625692e 100644 --- a/cmdline/snapraid.c +++ b/cmdline/snapraid.c @@ -1061,6 +1061,8 @@ int snapraid_main(int argc, char* argv[]) } } + msg_fatal_stderr = !opt.gui; + os_init(OS_INIT_OPT_AVOID_SLEEP | (opt.force_scan_winfind ? OS_INIT_OPT_WINFIND : 0)); app_init(); raid_init(); diff --git a/cmdline/support.c b/cmdline/support.c index dd5fe9e4..62188239 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -293,6 +293,7 @@ void log_error_errno(int err, const char* name) /* print */ int msg_level = 0; +int msg_fatal_stderr = 1; FILE* stdlog = 0; int msg_line_prev = 0; /**< Previous line width on stdout */ int msg_line_curr = 0; /**< Current line width on stdout */ @@ -393,15 +394,18 @@ void vlog_fatal(int err, const char* format, va_list ap, const char* post) fflush(stdlog); } - va_list ap_copy2; - va_copy(ap_copy2, ap); - vmsg(stderr, format, ap_copy2); - va_end(ap_copy2); + /* GUI consumers read tagged fatal messages from the log and must not receive a duplicate raw copy. */ + if (!stdlog || msg_fatal_stderr) { + va_list ap_copy2; + va_copy(ap_copy2, ap); + vmsg(stderr, format, ap_copy2); + va_end(ap_copy2); - if (post) - msg(stderr, "%s", post); + if (post) + msg(stderr, "%s", post); - fflush(stderr); + fflush(stderr); + } unlock_msg(); } diff --git a/cmdline/support.h b/cmdline/support.h index e997b7e0..dbc551a2 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -92,7 +92,8 @@ typedef void log_ptr(int err, const char* format, ...) __attribute__((format(att * * Messages printed before an early termination. * - * These messages go in the log file and in stderr unconditionally. + * These messages go in the log file and in stderr, except in GUI mode + * when a log is configured, where only the tagged log message is emitted. */ void vlog_fatal(int err, const char* format, va_list ap, const char* post); void log_fatal(int err, const char* format, ...) __attribute__((format(attribute_printf, 2, 3))); @@ -176,6 +177,11 @@ typedef void msg_ptr(const char* format, ...) __attribute__((format(attribute_pr */ extern int msg_level; +/** + * Emit fatal messages on stderr also when a log is configured. + */ +extern int msg_fatal_stderr; + /** * State messages. *