kamailio: add patch fixing fragile kamcmd
[feed/telephony.git] / net / kamailio / patches / 170-app_python3-use-new-Python-3.10-API-functions-for-tr.patch
1 From b8bf86eb11a17c853450e5c7f81d2446cf719fbc Mon Sep 17 00:00:00 2001
2 From: Daniel-Constantin Mierla <miconda@gmail.com>
3 Date: Thu, 21 Jul 2022 20:15:29 +0200
4 Subject: [PATCH] app_python3: use new Python 3.10+ API functions for tracking
5 execution
6
7 - GH #3187
8 ---
9 src/modules/app_python3/apy_kemi.c | 23 ++++++++++++++++++++++-
10 1 file changed, 22 insertions(+), 1 deletion(-)
11
12 --- a/src/modules/app_python3/apy_kemi.c
13 +++ b/src/modules/app_python3/apy_kemi.c
14 @@ -1810,6 +1810,9 @@ PyObject *sr_apy_kemi_exec_func(PyObject
15 PyObject *ret = NULL;
16 PyThreadState *pstate = NULL;
17 PyFrameObject *pframe = NULL;
18 +#if PY_VERSION_HEX >= 0x03100000
19 + PyCodeObject *pcode = NULL;
20 +#endif
21 struct timeval tvb = {0}, tve = {0};
22 struct timezone tz;
23 unsigned int tdiff;
24 @@ -1832,10 +1835,27 @@ PyObject *sr_apy_kemi_exec_func(PyObject
25 + (tve.tv_usec - tvb.tv_usec);
26 if(tdiff >= cfg_get(core, core_cfg, latency_limit_action)) {
27 pstate = PyThreadState_GET();
28 - if (pstate != NULL && pstate->frame != NULL) {
29 + if (pstate != NULL) {
30 +#if PY_VERSION_HEX >= 0x03100000
31 + pframe = PyThreadState_GetFrame(pstate);
32 + if(pframe != NULL) {
33 + pcode = PyFrame_GetCode(pframe);
34 + }
35 +#else
36 pframe = pstate->frame;
37 +#endif
38 }
39
40 +#if PY_VERSION_HEX >= 0x03100000
41 + LOG(cfg_get(core, core_cfg, latency_log),
42 + "alert - action KSR.%s%s%s(...)"
43 + " took too long [%u ms] (file:%s func:%s line:%d)\n",
44 + (ket->mname.len>0)?ket->mname.s:"",
45 + (ket->mname.len>0)?".":"", ket->fname.s, tdiff,
46 + (pcode)?PyBytes_AsString(pcode->co_filename):"",
47 + (pcode)?PyBytes_AsString(pcode->co_name):"",
48 + (pframe)?PyFrame_GetLineNumber(pframe):0);
49 +#else
50 LOG(cfg_get(core, core_cfg, latency_log),
51 "alert - action KSR.%s%s%s(...)"
52 " took too long [%u ms] (file:%s func:%s line:%d)\n",
53 @@ -1844,6 +1864,7 @@ PyObject *sr_apy_kemi_exec_func(PyObject
54 (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_filename):"",
55 (pframe && pframe->f_code)?PyBytes_AsString(pframe->f_code->co_name):"",
56 (pframe && pframe->f_code)?PyCode_Addr2Line(pframe->f_code, pframe->f_lasti):0);
57 +#endif
58 }
59 }
60