From 64a2b7aaa303be0b407508747bfc96c1c656f1e2 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Thu, 12 Jan 2023 17:40:53 +0100 Subject: 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. --- sysdep/unix/log.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'sysdep/unix/log.c') diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index 4e9df069..53122aee 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -31,6 +31,7 @@ #include "lib/lists.h" #include "sysdep/unix/unix.h" +static int dbg_fd = -1; static FILE *dbgf; static list *current_log_list; static char *current_syslog_name; /* NULL -> syslog closed */ @@ -324,6 +325,21 @@ debug(const char *msg, ...) 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 * default_log_list(int initial, const char **syslog_name) { @@ -422,8 +438,10 @@ done: void log_init_debug(char *f) { + dbg_fd = -1; if (dbgf && dbgf != stderr) fclose(dbgf); + if (!f) dbgf = NULL; 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)); exit(1); } + if (dbgf) + { setvbuf(dbgf, NULL, _IONBF, 0); + dbg_fd = fileno(dbgf); + } } -- cgit v1.2.3