]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Log message before aborting
authorMike Crute <mike@crute.us>
Thu, 12 Jan 2023 16:40:53 +0000 (17:40 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 12 Jan 2023 16:40:53 +0000 (17:40 +0100)
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.

lib/birdlib.h
sysdep/unix/io.c
sysdep/unix/log.c

index 81d4908acd9d1bf188622b505298dc33f780597c..e03bd0b2f5e7a37bd1714ad2de351076c7919cf4 100644 (file)
@@ -160,6 +160,7 @@ void bug(const char *msg, ...) NORET;
 #define L_BUG "\011"                   /* BIRD bugs */
 
 void debug(const char *msg, ...);      /* Printf to debug output */
+void debug_safe(const char *msg);      /* Printf to debug output, async-safe */
 
 /* Debugging */
 
index 810e782d9be518e96aaf81e823b7e23fb6d91391..e131ca41ff460ae9e9d4b9fc94c831c7ea936adc 100644 (file)
@@ -2128,6 +2128,8 @@ watchdog_sigalrm(int sig UNUSED)
   config->latency_limit = 0xffffffff;
   io_update_time();
 
+  debug_safe("Watchdog timer timed out\n");
+
   /* We want core dump */
   abort();
 }
index 4e9df069eccf6290d405e44658ef897944b53c62..53122aee3b98696cec871c2bc68f2cdf0b49d192 100644 (file)
@@ -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);
+  }
 }