Module: kamailio
Branch: master
Commit: f8b8cecb7d713b37e3184b4720c992296005a427
URL: 
https://github.com/kamailio/kamailio/commit/f8b8cecb7d713b37e3184b4720c992296005a427

Author: AnthonyA <[email protected]>
Committer: AnthonyA <[email protected]>
Date: 2018-03-03T21:57:28+08:00

app_python: improve exception debugging

- print method name and arg on error

---

Modified: src/modules/app_python/python_exec.c
Modified: src/modules/app_python/python_support.c
Modified: src/modules/app_python/python_support.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/f8b8cecb7d713b37e3184b4720c992296005a427.diff
Patch: 
https://github.com/kamailio/kamailio/commit/f8b8cecb7d713b37e3184b4720c992296005a427.patch

---

diff --git a/src/modules/app_python/python_exec.c 
b/src/modules/app_python/python_exec.c
index 91c93d0e18..f5f4d02532 100644
--- a/src/modules/app_python/python_exec.c
+++ b/src/modules/app_python/python_exec.c
@@ -146,7 +146,7 @@ int apy_exec(sip_msg_t *_msg, char *fname, char *fparam, 
int emode)
        Py_DECREF(pFunc);
        if (PyErr_Occurred()) {
                Py_XDECREF(pResult);
-               python_handle_exception("python_exec2");
+               python_handle_exception("apy_exec: %s(%s)", fname, fparam);
                _sr_apy_env.msg = bmsg;
                goto err;
        }
diff --git a/src/modules/app_python/python_support.c 
b/src/modules/app_python/python_support.c
index 0a57068719..8db77af937 100644
--- a/src/modules/app_python/python_support.c
+++ b/src/modules/app_python/python_support.c
@@ -29,6 +29,8 @@
 #include "app_python_mod.h"
 #include "python_support.h"
 
+static char *make_message(const char *fmt, va_list ap);
+
 void python_handle_exception(const char *fmt, ...)
 {
        PyObject *pResult;
@@ -40,6 +42,7 @@ void python_handle_exception(const char *fmt, ...)
        int i;
        char *srcbuf;
        int exc_exit = 0;
+       va_list ap;
 
        // We don't want to generate traceback when no errors occurred
        if (!PyErr_Occurred())
@@ -47,8 +50,11 @@ void python_handle_exception(const char *fmt, ...)
 
        if (fmt == NULL)
                srcbuf = NULL;
-       else
-               srcbuf = make_message(fmt);
+       else {
+               va_start(fmt, ap);
+               srcbuf = make_message(fmt, ap);
+               va_end(ap);
+       }
 
        PyErr_Fetch(&exception, &v, &tb);
        PyErr_Clear();
@@ -184,12 +190,11 @@ PyObject *InitTracebackModule()
 }
 
 
-char *make_message(const char *fmt, ...)
+static char *make_message(const char *fmt, va_list ap)
 {
        int n;
        size_t size;
        char *p, *np;
-       va_list ap;
 
        size = 100;     /* Guess we need no more than 100 bytes. */
        p = (char *)pkg_realloc(NULL, size * sizeof(char));
@@ -203,9 +208,7 @@ char *make_message(const char *fmt, ...)
 
        while (1)
        {
-               va_start(ap, fmt);
                n = vsnprintf(p, size, fmt, ap);
-               va_end(ap);
 
                if (n > -1 && n < size)
                        return p;
diff --git a/src/modules/app_python/python_support.h 
b/src/modules/app_python/python_support.h
index 032340dcdd..4d25564119 100644
--- a/src/modules/app_python/python_support.h
+++ b/src/modules/app_python/python_support.h
@@ -28,7 +28,6 @@
 PyObject *format_exc_obj;
 
 void python_handle_exception(const char *, ...);
-char *make_message(const char *fmt, ...);
 
 PyObject *InitTracebackModule(void);
 char *get_class_name(PyObject *);


_______________________________________________
Kamailio (SER) - Development Mailing List
[email protected]
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to