]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/signal.c
Add missing files for xattr and eliminate a few compiler complaints
[bacula/bacula] / bacula / src / lib / signal.c
index 3b34cd15256229fc8cdd7416c2c877a4d6b946dc..1705942275f4b993fd53b1a25e77896f2a91b35c 100644 (file)
@@ -1,14 +1,14 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,7 +20,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
@@ -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,42 @@ 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/%s.%d.bactrace", 
+            working_directory, my_name, getpid());
+   FILE *fp = fopen(buf, "ab") ;
+   if (!fp) {
+      fp = stderr;
+   }
+   
+   fprintf(stderr, "Dumping: %s\n", buf);
+
+   /* 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
  */
@@ -91,7 +128,10 @@ extern "C" void signal_handler(int sig)
    if (sig == SIGTERM) {
 //    Emsg1(M_TERM, -1, "Shutting down Bacula service: %s ...\n", my_name);
    } else {
-      Emsg2(M_FATAL, -1, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig));
+/* ***FIXME*** Display a message without taking any lock in the system
+ *    Emsg2(M_FATAL, -1, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig));
+ */
+      fprintf(stderr, _("Bacula interrupted by signal %d: %s\n"), sig, get_signal_name(sig));
    }
 
 #ifdef TRACEBACK
@@ -156,6 +196,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 +206,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 {
@@ -174,9 +217,9 @@ extern "C" void signal_handler(int sig)
          bmicrosleep(30, 0);
       }
       fprintf(stderr, _("It looks like the traceback worked ...\n"));
+      dbg_print_bacula();
    }
 #endif
-
    exit_handler(sig);
 }