diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-07-21 12:11:52 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:29:53 -0500 |
commit | a369f0ecaf35fb49652873c4c1ddcaf28629c26e (patch) | |
tree | 1a7336cb6826733d19fc5744e753c558a8ba9148 /source4/lib | |
parent | f8c1258d01fa631b719579e186b28027a34887cf (diff) | |
download | samba-a369f0ecaf35fb49652873c4c1ddcaf28629c26e.tar.gz samba-a369f0ecaf35fb49652873c4c1ddcaf28629c26e.tar.bz2 samba-a369f0ecaf35fb49652873c4c1ddcaf28629c26e.zip |
r8678: setup for gdb backtrace in 'make test'
(This used to be commit acf8c8fd4995acef47390df5a7d4e611c597367d)
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/cmdline/popt_common.c | 3 | ||||
-rw-r--r-- | source4/lib/fault.c | 35 |
2 files changed, 18 insertions, 20 deletions
diff --git a/source4/lib/cmdline/popt_common.c b/source4/lib/cmdline/popt_common.c index e39c8e964d..53bb7b5a8c 100644 --- a/source4/lib/cmdline/popt_common.c +++ b/source4/lib/cmdline/popt_common.c @@ -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 diff --git a/source4/lib/fault.c b/source4/lib/fault.c index f3a9e78f39..22efb4825d 100644 --- a/source4/lib/fault.c +++ b/source4/lib/fault.c @@ -23,14 +23,13 @@ #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 |