0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

Log message before aborting

Log message before aborting due to watchdog timeout. We have to use
async-safe write to debug log, as it is done in signal handler.

Minor changes from committer.
This commit is contained in:
Mike Crute 2023-01-12 17:40:53 +01:00 committed by Ondrej Zajicek
parent e20bef69cc
commit 64a2b7aaa3
3 changed files with 25 additions and 0 deletions

View File

@ -160,6 +160,7 @@ void bug(const char *msg, ...) NORET;
#define L_BUG "\011" /* BIRD bugs */ #define L_BUG "\011" /* BIRD bugs */
void debug(const char *msg, ...); /* Printf to debug output */ void debug(const char *msg, ...); /* Printf to debug output */
void debug_safe(const char *msg); /* Printf to debug output, async-safe */
/* Debugging */ /* Debugging */

View File

@ -2128,6 +2128,8 @@ watchdog_sigalrm(int sig UNUSED)
config->latency_limit = 0xffffffff; config->latency_limit = 0xffffffff;
io_update_time(); io_update_time();
debug_safe("Watchdog timer timed out\n");
/* We want core dump */ /* We want core dump */
abort(); abort();
} }

View File

@ -31,6 +31,7 @@
#include "lib/lists.h" #include "lib/lists.h"
#include "sysdep/unix/unix.h" #include "sysdep/unix/unix.h"
static int dbg_fd = -1;
static FILE *dbgf; static FILE *dbgf;
static list *current_log_list; static list *current_log_list;
static char *current_syslog_name; /* NULL -> syslog closed */ static char *current_syslog_name; /* NULL -> syslog closed */
@ -324,6 +325,21 @@ debug(const char *msg, ...)
va_end(args); va_end(args);
} }
/**
* debug_safe - async-safe write to debug output
* @msg: a string message
*
* This function prints the message @msg to the debugging output in a
* way that is async safe and can be used in signal handlers. No newline
* character is appended.
*/
void
debug_safe(const char *msg)
{
if (dbg_fd >= 0)
write(dbg_fd, msg, strlen(msg));
}
static list * static list *
default_log_list(int initial, const char **syslog_name) default_log_list(int initial, const char **syslog_name)
{ {
@ -422,8 +438,10 @@ done:
void void
log_init_debug(char *f) log_init_debug(char *f)
{ {
dbg_fd = -1;
if (dbgf && dbgf != stderr) if (dbgf && dbgf != stderr)
fclose(dbgf); fclose(dbgf);
if (!f) if (!f)
dbgf = NULL; dbgf = NULL;
else if (!*f) else if (!*f)
@ -434,6 +452,10 @@ log_init_debug(char *f)
fprintf(stderr, "bird: Unable to open debug file %s: %s\n", f, strerror(errno)); fprintf(stderr, "bird: Unable to open debug file %s: %s\n", f, strerror(errno));
exit(1); exit(1);
} }
if (dbgf) if (dbgf)
{
setvbuf(dbgf, NULL, _IONBF, 0); setvbuf(dbgf, NULL, _IONBF, 0);
dbg_fd = fileno(dbgf);
}
} }