Exit code and logging invariants for log_fatal and hardware log_error
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-09-20 15:56:14 +02:00
parent c2d46f4039
commit 3968678216
16 changed files with 193 additions and 114 deletions

View file

@ -297,6 +297,18 @@ 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 */
static unsigned log_hardware_error_count = 0;
unsigned log_hardware_errors(void)
{
unsigned count;
lock_msg();
count = log_hardware_error_count;
unlock_msg();
return count;
}
/*
* Note that in the following functions we always flush both
@ -379,12 +391,14 @@ void vlog_fatal(int err, const char* format, va_list ap, const char* post)
lock_msg();
if (is_hw(err))
++log_hardware_error_count;
if (stdlog) {
if (is_hw(err))
log_failed = fprintf(stdlog, "msg:fatal_hardware: ") < 0;
else
log_failed = fprintf(stdlog, "msg:fatal: ") < 0;
va_list ap_copy;
va_copy(ap_copy, ap);
if (vfprintf(stdlog, format, ap_copy) < 0)
@ -427,6 +441,9 @@ void vlog_error(int err, const char* format, va_list ap, const char* post)
{
lock_msg();
if (is_hw(err))
++log_hardware_error_count;
if (stdlog) {
if (is_hw(err))
fprintf(stdlog, "msg:error_hardware: ");
@ -470,6 +487,9 @@ void vlog_info(int err, const char* format, va_list ap, const char* post)
{
lock_msg();
if (is_hw(err))
++log_hardware_error_count;
if (stdlog) {
if (is_hw(err))
fprintf(stdlog, "msg:error_hardware: "); /* we never expect an hardware error */
@ -536,6 +556,9 @@ void log_expected(int err, const char* format, ...)
lock_msg();
if (is_hw(err))
++log_hardware_error_count;
if (stdlog) {
if (is_hw(err))
fprintf(stdlog, "msg:error_hardware: "); /* we never expect an hardware error */