lib/util/fault.c: Unify printing of the stack trace with the INTERNAL ERROR string
authorAndrew Bartlett <abartlet@samba.org>
Tue, 25 Feb 2020 23:02:36 +0000 (12:02 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 27 Feb 2020 05:09:44 +0000 (05:09 +0000)
We can diverged into the s3 and lib/fault panic action stuff once
we have printed the backtrace.

Our tests require we use the word PANIC, and some administrative scripts
might look for similar things, so keep those words.

The use of DEBUG(0, ... is deliberate to keep the output
of the PANIC line as consistent as possible with the historical smbd output.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Thu Feb 27 05:09:44 UTC 2020 on sn-devel-184

lib/util/fault.c
lib/util/fault.h
source3/lib/util.c
source3/utils/regedit.c

index a34f9eedb316579dfd1da8f456de8022520b501d..b1da1bb4121263a0829710609ba7971f1a7c1ce3 100644 (file)
@@ -122,10 +122,6 @@ _PUBLIC_ const char *panic_action = NULL;
 static void smb_panic_default(const char *why) _NORETURN_;
 static void smb_panic_default(const char *why)
 {
-       DBG_ERR("PANIC (pid %llu): %s\n",
-                   (unsigned long long)getpid(), why);
-       log_stack_trace();
-
 #if defined(HAVE_PRCTL) && defined(PR_SET_PTRACER)
        /*
         * Make sure all children can attach a debugger.
@@ -158,20 +154,31 @@ static void smb_panic_default(const char *why)
        abort();
 }
 
-
-/**
-   Something really nasty happened - panic !
-**/
-_PUBLIC_ void smb_panic(const char *why)
+_PUBLIC_ void smb_panic_log(const char *why)
 {
        DEBUGSEP(0);
-       DEBUG(0,("INTERNAL ERROR: %s in pid %d (%s)",why,(int)getpid(),SAMBA_VERSION_STRING));
-       DEBUG(0,("\nIf you are running a recent Samba version, and "
+       DEBUG(0,("INTERNAL ERROR: %s in pid %lld (%s)\n",
+                why,
+                (unsigned long long)getpid(),
+                SAMBA_VERSION_STRING));
+       DEBUG(0,("If you are running a recent Samba version, and "
                 "if you think this problem is not yet fixed in the "
                 "latest versions, please consider reporting this "
                 "bug, see "
                 "https://wiki.samba.org/index.php/Bug_Reporting\n"));
        DEBUGSEP(0);
+       DEBUG(0,("PANIC (pid %llu): %s in " SAMBA_VERSION_STRING "\n",
+                (unsigned long long)getpid(), why));
+
+       log_stack_trace();
+}
+
+/**
+   Something really nasty happened - panic !
+**/
+_PUBLIC_ void smb_panic(const char *why)
+{
+       smb_panic_log(why);
 
        if (fault_state.panic_handler) {
                fault_state.panic_handler(why);
index dfa339b7650980a1ee9c30651e3cd32457f179fa..f3b1666a17216beaec52c4cdfe0c840915cd2052 100644 (file)
@@ -52,6 +52,7 @@ void fault_configure(smb_panic_handler_t panic_handler);
 void fault_setup(void);
 void fault_setup_disable(void);
 _NORETURN_ void smb_panic(const char *reason);
+void smb_panic_log(const char *reason);
 
 void log_stack_trace(void);
 
index 4b276415378b619b099962c716c6ed8b9cb52295..4d5f611ac82d13ebadfa50092a9fefc39a622208 100644 (file)
@@ -826,10 +826,6 @@ void smb_panic_s3(const char *why)
        char *cmd;
        int result;
 
-       DEBUG(0,("PANIC (pid %llu): %s\n",
-                   (unsigned long long)getpid(), why));
-       log_stack_trace();
-
 #if defined(HAVE_PRCTL) && defined(PR_SET_PTRACER)
        /*
         * Make sure all children can attach a debugger.
index 2f5e0fcc1eb1c0975254e6529a89628b5745610e..ce50f65799170af43bd09e898963f076508babd2 100644 (file)
@@ -681,6 +681,7 @@ int regedit_getch(void)
 static void regedit_panic_handler(const char *msg)
 {
        endwin();
+       smb_panic_log(msg);
        smb_panic_s3(msg);
 }