r8678: setup for gdb backtrace in 'make test'
authorAndrew Tridgell <tridge@samba.org>
Thu, 21 Jul 2005 12:11:52 +0000 (12:11 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:29:53 +0000 (13:29 -0500)
(This used to be commit acf8c8fd4995acef47390df5a7d4e611c597367d)

source4/client/smbspool.c
source4/lib/cmdline/popt_common.c
source4/lib/fault.c
source4/script/gdb_backtrace [new file with mode: 0755]
source4/script/tests/selftest.sh
source4/scripting/ejs/smbscript.c
source4/smbd/server.c

index 21dc5c0e1082c4bd04cfa02f3e98efb41632e4a5..cb95c0d5a3151e2636d926dd143e6e7a26c2eb3d 100644 (file)
@@ -175,7 +175,7 @@ static int          smb_print(struct smbcli_state *, char *, FILE *);
   * Setup the SAMBA server state...
   */
 
-  setup_logging("smbspool", DEBUG_STDOUT);
+  setup_logging(argv[0], DEBUG_STDOUT);
 
   if (!lp_load()) {
          fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", lp_config_file());
index e39c8e964d44425a93de14ab0990ec99e154eb7f..53bb7b5a8cf2155e181dab55a407923fde9eb639 100644 (file)
@@ -48,6 +48,9 @@ static void popt_common_callback(poptContext con,
                           const char *arg, const void *data)
 {
        const char *pname;
+
+       /* setup for panics */
+       fault_setup(poptGetInvocationName(con));
        
        if (reason == POPT_CALLBACK_REASON_POST) {
                /* Hook any 'every Samba program must do this, after
index f3a9e78f39895a1d2726a94c890a0e36d4e8f2d7..22efb4825d79337e8534b4bef995a90ef91a848c 100644 (file)
 #include "system/wait.h"
 #include "system/filesys.h"
 
-static void (*cont_fn)(void *);
-
 /* the registered fault handler */
 static struct {
        const char *name;
        void (*fault_handler)(int sig);
 } fault_handlers;
 
+static const char *progname;
 
 #ifdef HAVE_BACKTRACE
 #include <execinfo.h>
@@ -111,8 +110,16 @@ void smb_panic(const char *why)
        int result;
 
        if (cmd && *cmd) {
-               DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmd));
-               result = system(cmd);
+               char pidstr[20];
+               char cmdstring[200];
+               safe_strcpy(cmdstring, cmd, sizeof(cmdstring));
+               snprintf(pidstr, sizeof(pidstr), "%u", getpid());
+               all_string_sub(cmdstring, "%PID%", pidstr, sizeof(cmdstring));
+               if (progname) {
+                       all_string_sub(cmdstring, "%PROG%", progname, sizeof(cmdstring));
+               }
+               DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmdstring));
+               result = system(cmdstring);
 
                if (result == -1)
                        DEBUG(0, ("smb_panic(): fork failed in panic action: %s\n",
@@ -147,19 +154,6 @@ static void fault_report(int sig)
 
        smb_panic("internal error");
 
-       if (cont_fn) {
-               cont_fn(NULL);
-#ifdef SIGSEGV
-               CatchSignal(SIGSEGV,SIGNAL_CAST SIG_DFL);
-#endif
-#ifdef SIGBUS
-               CatchSignal(SIGBUS,SIGNAL_CAST SIG_DFL);
-#endif
-#ifdef SIGABRT
-               CatchSignal(SIGABRT,SIGNAL_CAST SIG_DFL);
-#endif
-               return; /* this should cause a core dump */
-       }
        exit(1);
 }
 
@@ -179,10 +173,11 @@ static void sig_fault(int sig)
 /*******************************************************************
 setup our fault handlers
 ********************************************************************/
-void fault_setup(void (*fn)(void *))
+void fault_setup(const char *pname)
 {
-       cont_fn = fn;
-
+       if (progname == NULL) {
+               progname = pname;
+       }
 #ifdef SIGSEGV
        CatchSignal(SIGSEGV,SIGNAL_CAST sig_fault);
 #endif
diff --git a/source4/script/gdb_backtrace b/source4/script/gdb_backtrace
new file mode 100755 (executable)
index 0000000..0ba8c0e
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# we want everything on stderr, so the program is not disturbed
+exec 1>&2
+
+PID=$1
+PROG=$2
+
+TMPFILE=/tmp/gdb.$$
+cat << EOF  > $TMPFILE
+set height 1000
+bt full
+quit
+EOF
+
+gdb -batch -x $TMPFILE $PROG $PID < /dev/null 
+/bin/rm -f $TMPFILE
index 3f1bea75f1e1c31bc0eaebde9dd8fb1b4a80af1d..673e6a06a8f1df0893f5b4541aeef0d4bc14e898 100755 (executable)
@@ -92,6 +92,7 @@ cat >$CONFFILE<<EOF
        name resolve order = bcast
        interfaces = lo*
        tls enabled = $TLS_ENABLED
+       panic action = $SRCDIR/script/gdb_backtrace %PID% %PROG%
 
 [tmp]
        path = $TMPDIR
index c6155dcbeb2781b0cc533afb150f0616930c544f..b16536a5752bc3f5ad34ed72ad2372992578c9e2 100644 (file)
@@ -45,6 +45,7 @@ void ejs_exception(const char *reason)
        struct MprVar *return_var;
        int exit_status, i;
 
+       fault_setup(argv[0]);
        smbscript_init_subsystems;
        mprSetCtx(mem_ctx);
 
index f5f37a55cfbd1e10963c2ba84880c627858d7608..a176b59d8d1ca887f636e318be127cdc7bb81ec6 100644 (file)
@@ -96,8 +96,6 @@ static void cleanup_tmp_files(void)
 */
 static void setup_signals(void)
 {
-       fault_setup(NULL);
-       
        /* we are never interested in SIGPIPE */
        BlockSignals(True,SIGPIPE);
 
@@ -175,7 +173,7 @@ static int binary_smbd_main(int argc, const char *argv[])
 
        poptFreeContext(pc);
 
-       setup_logging(NULL, interactive?DEBUG_STDOUT:DEBUG_FILE);
+       setup_logging(argv[0], interactive?DEBUG_STDOUT:DEBUG_FILE);
        setup_signals();
 
        /* we want total control over the permissions on created files,