]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/signal.c
ebl Add Plugin debug after a fatal signal.
[bacula/bacula] / bacula / src / lib / signal.c
index 51fe13a83d4d99a12fcf45ffec358bc13848a7b6..941c6f709185dabd92ab27ee4413f6ea6925410f 100644 (file)
@@ -53,6 +53,7 @@
 extern char my_name[];
 extern char *exepath;
 extern char *exename;
+extern void print_jcr_dbg();
 
 static const char *sig_names[BA_NSIG+1];
 
@@ -71,6 +72,40 @@ const char *get_signal_name(int sig)
    }
 }
 
+/* defined in jcr.c */
+extern void _dbg_print_jcr(FILE *fp);
+/* defined in plugin.c */
+extern void _dbg_print_plugin(FILE *fp);
+
+/*
+ * !!! WARNING !!! 
+ *
+ * This function should be used ONLY after a violent signal. We walk through the
+ * JCR chain without doing any lock, bacula should not be running.
+ */
+static void dbg_print_bacula()
+{
+   char buf[512];
+
+   snprintf(buf, sizeof(buf), "%s/bacula.%d.bactrace", 
+            working_directory, getpid());
+   FILE *fp = fopen(buf, "ab") ;
+   if (!fp) {
+      fp = stderr;
+   }
+
+   /* Print also B_DB and RWLOCK structure 
+    * Can add more info about JCR with dbg_jcr_add_hook()
+    */
+   _dbg_print_jcr(fp);
+
+   _dbg_print_plugin(fp);
+
+   if (fp != stderr) {
+      fclose(fp);
+   }
+}
+
 /*
  * Handle signals here
  */
@@ -156,6 +191,7 @@ extern "C" void signal_handler(int sig)
       default:                        /* parent */
          break;
       }
+
       /* Parent continue here, waiting for child */
       sigdefault.sa_flags = 0;
       sigdefault.sa_handler = SIG_DFL;
@@ -165,8 +201,10 @@ extern "C" void signal_handler(int sig)
       if (pid > 0) {
          Dmsg0(500, "Doing waitpid\n");
          waitpid(pid, NULL, 0);       /* wait for child to produce dump */
-         fprintf(stderr, _("Traceback complete, attempting cleanup ...\n"));
          Dmsg0(500, "Done waitpid\n");
+         fprintf(stderr, _("Traceback complete, attempting cleanup ...\n"));
+         /* print information about the current state into working/<file>.bactrace */
+         dbg_print_bacula();
          exit_handler(sig);           /* clean up if possible */
          Dmsg0(500, "Done exit_handler\n");
       } else {