silcd: Save debug message in ring buffer
authorPekka Riikonen <priikone@silcnet.org>
Tue, 2 Jun 2009 05:01:25 +0000 (08:01 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 2 Jun 2009 05:01:25 +0000 (08:01 +0300)
In debug version save 3000 last debug messages in ring buffer so that they
are available in core files.

apps/silcd/command.c
apps/silcd/silcd.c

index 9c1fc4e2504604bbfce5b0bdb4229e0ed31de60c..597f042efadd176e17c796eb46352710dbd38663 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2008 Pekka Riikonen
+  Copyright (C) 1997 - 2009 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -339,7 +339,7 @@ SILC_TASK_CALLBACK(silc_server_command_pending_timeout)
   SilcBuffer tmpreply;
   int i;
 
-  SILC_LOG_DEBUG(("Timeout pending command"));
+  SILC_LOG_DEBUG(("Timeout pending command %p", reply));
 
   /* Allocate temporary and bogus command reply context */
   cmdr = silc_calloc(1, sizeof(*cmdr));
index cc4d7ff39ab9dc886991d8d80621ef87de15642b..d02d51298641cc66cc3507276e890297766f5601 100644 (file)
@@ -557,6 +557,28 @@ void silc_server_stderr(SilcLogType type, char *message)
   }
 }
 
+#ifdef SILC_DEBUG
+#define NUM_DEBUGS 3000
+static char debugs[NUM_DEBUGS][128];
+static int cur_debug = 0;
+
+SilcBool silc_server_debug_callback(char *file, char *function, int line,
+                                   char *message, void *context)
+{
+  SilcTimeStruct curtime;
+
+  /* Save the message to ring buffer */
+  silc_time_value(0, &curtime);
+  silc_snprintf(debugs[cur_debug % NUM_DEBUGS], sizeof(debugs[0]),
+               "%02d:%02d:%02d %s:%d: %s", curtime.hour,
+               curtime.minute, curtime.second, function, line,
+               message);
+  cur_debug++;
+
+  return FALSE;
+}
+#endif /* SILC_DEBUG */
+
 int main(int argc, char **argv)
 {
   int ret, opt, option_index;
@@ -565,6 +587,10 @@ int main(int argc, char **argv)
   char *silcd_config_file = NULL;
   struct sigaction sa;
 
+#ifdef SILC_DEBUG
+  silc_log_set_debug_callbacks(silc_server_debug_callback, NULL, NULL, NULL);
+#endif /* SILC_DEBUG */
+
   /* Parse command line arguments */
   if (argc > 1) {
 #ifdef HAVE_GETOPT_LONG