* hb_error ********************************************************************** * Using whatever output is available display this error. *********************************************************************/
| 4547 | * Using whatever output is available display this error. |
| 4548 | *********************************************************************/ |
| 4549 | void hb_error( char * log, ... ) |
| 4550 | { |
| 4551 | char string[181]; /* 180 chars + \0 */ |
| 4552 | char rep_string[181]; |
| 4553 | static char last_string[181]; |
| 4554 | static int last_error_count = 0; |
| 4555 | static uint64_t last_series_error_time = 0; |
| 4556 | static hb_lock_t *mutex = 0; |
| 4557 | va_list args; |
| 4558 | uint64_t time_now; |
| 4559 | |
| 4560 | /* Convert the message to a string */ |
| 4561 | va_start( args, log ); |
| 4562 | vsnprintf( string, 180, log, args ); |
| 4563 | va_end( args ); |
| 4564 | |
| 4565 | if( !mutex ) |
| 4566 | { |
| 4567 | mutex = hb_lock_init(); |
| 4568 | } |
| 4569 | |
| 4570 | hb_lock( mutex ); |
| 4571 | |
| 4572 | time_now = hb_get_date(); |
| 4573 | |
| 4574 | if( strcmp( string, last_string) == 0 ) |
| 4575 | { |
| 4576 | /* |
| 4577 | * The last error and this one are the same, don't log it |
| 4578 | * just count it instead, unless it was more than one second |
| 4579 | * ago. |
| 4580 | */ |
| 4581 | last_error_count++; |
| 4582 | if( last_series_error_time + ( 1000 * 1 ) > time_now ) |
| 4583 | { |
| 4584 | hb_unlock( mutex ); |
| 4585 | return; |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | /* |
| 4590 | * A new error, or the same one more than 10sec since the last one |
| 4591 | * did we have any of the same counted up? |
| 4592 | */ |
| 4593 | if( last_error_count > 0 ) |
| 4594 | { |
| 4595 | /* |
| 4596 | * Print out the last error to ensure context for the last |
| 4597 | * repeated message. |
| 4598 | */ |
| 4599 | if( error_handler ) |
| 4600 | { |
| 4601 | error_handler( last_string ); |
| 4602 | } else { |
| 4603 | hb_log( "%s", last_string ); |
| 4604 | } |
| 4605 | |
| 4606 | if( last_error_count > 1 ) |
no test coverage detected