[Patches] No backtrace/panic action called from python tools (bug #13469)

Stefan Metzmacher metze at samba.org
Tue Jun 12 05:48:15 UTC 2018


Hi,

here're patches to call fault_setup() in our python commandline tools,
e.g. samba-tool.

Please review and push:-)

Thanks!
metze
-------------- next part --------------
From 4c4ca4da962d1a55e97c9b3ae59c1d03ac84659a Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Fri, 25 May 2018 07:52:02 +0200
Subject: [PATCH 1/2] python: export fault_setup() to python bindings

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13469

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/pyglue.c          | 12 ++++++++++++
 python/samba/__init__.py |  1 +
 2 files changed, 13 insertions(+)

diff --git a/python/pyglue.c b/python/pyglue.c
index 68b14a072e45..1b111866f223 100644
--- a/python/pyglue.c
+++ b/python/pyglue.c
@@ -170,6 +170,16 @@ static PyObject *py_get_debug_level(PyObject *self)
 	return PyInt_FromLong(DEBUGLEVEL);
 }
 
+static PyObject *py_fault_setup(PyObject *self)
+{
+	static bool done;
+	if (!done) {
+		fault_setup();
+		done = true;
+	}
+	Py_RETURN_NONE;
+}
+
 static PyObject *py_is_ntvfs_fileserver_built(PyObject *self)
 {
 #ifdef WITH_NTVFS_FILESERVER
@@ -339,6 +349,8 @@ static PyMethodDef py_misc_methods[] = {
 		"set debug level" },
 	{ "get_debug_level", (PyCFunction)py_get_debug_level, METH_NOARGS,
 		"get debug level" },
+	{ "fault_setup", (PyCFunction)py_fault_setup, METH_NOARGS,
+		"setup the default samba panic handler" },
 	{ "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
 		"interface_ips(lp_ctx[, all_interfaces) -> list_of_ifaces\n"
 		"\n"
diff --git a/python/samba/__init__.py b/python/samba/__init__.py
index 7b3c6538771d..1a3b24bca580 100644
--- a/python/samba/__init__.py
+++ b/python/samba/__init__.py
@@ -381,6 +381,7 @@ def arcfour_encrypt(key, data):
 
 version = _glue.version
 interface_ips = _glue.interface_ips
+fault_setup = _glue.fault_setup
 set_debug_level = _glue.set_debug_level
 get_debug_level = _glue.get_debug_level
 unix2nttime = _glue.unix2nttime
-- 
2.17.1


From 3e50b3a3e6f58064e41e9aea7fc531cdd306d366 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Fri, 25 May 2018 07:52:40 +0200
Subject: [PATCH 2/2] python: call fault_setup() if samba.getopt is used

This means we have a samba command line tool written in python,
e.g. samba-tool

We should get the samba typicall backtraces instead of
just "Segmentation fault (core dumped)".

Bug: https://bugzilla.samba.org/show_bug.cgi?id=13469

Signed-off-by: Stefan Metzmacher <metze at samba.org>
---
 python/samba/getopt.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/python/samba/getopt.py b/python/samba/getopt.py
index b33a5c07ba46..3c819aed61db 100644
--- a/python/samba/getopt.py
+++ b/python/samba/getopt.py
@@ -34,6 +34,8 @@ class SambaOptions(optparse.OptionGroup):
     """General Samba-related command line options."""
 
     def __init__(self, parser):
+        from samba import fault_setup
+        fault_setup()
         from samba.param import LoadParm
         optparse.OptionGroup.__init__(self, parser, "Samba Common Options")
         self.add_option("-s", "--configfile", action="callback",
-- 
2.17.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20180612/31fea0ae/signature.sig>


More information about the samba-technical mailing list