<div dir="ltr">Resent after signing up, due to original message being held for review for a week:<div><br></div><div><span style="font-family:arial,sans-serif;font-size:12.727272033691406px">Kamailio terminates (Signal 15) after app_python crashes (signal 7) when using call_function("append_hf") with more than 1 parameter.</span><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><div>Jul  9 13:53:18 vcr01 /usr/sbin/kamailio[2699]: ALERT: <core> [main.c:788]: handle_sigs(): child process 2707 exited by a signal 7</div>

<div>Jul  9 13:53:18 vcr01 /usr/sbin/kamailio[2699]: ALERT: <core> [main.c:791]: handle_sigs(): core was generated</div><div>Jul  9 13:53:18 vcr01 /usr/sbin/kamailio[2699]: INFO: <core> [main.c:803]: handle_sigs(): INFO: terminating due to SIGCHLD</div>

<div>Jul  9 13:53:18 vcr01 /usr/sbin/kamailio[2706]: INFO: <core> [main.c:854]: sig_usr(): INFO: signal 15 received</div><div><br></div><div>Actually, calling "remove_hf" with call_function seems to do exactly the same thing, though that is just with 1 param.</div>

<div><br></div><div>My problem is that I need to manipulate the Diversion headers (or rather, add a new Diversion header in the correct place (i.e. above the other Diversion header), as append_hf will always add it at the bottom.)</div>

<div><br></div><div>I've identified what part of the code makes it crash (debugging by returning early), and it seems to be the fixup part, which as far as I can tell has something to do with string formatting for kamailio:</div>

<div><div>    if (fexport->fixup != NULL) {</div><div>        if (i >= 3) {</div><div>            rval = fexport->fixup(&(act->val[3].u.data), 2);</div><div>            if (rval < 0) {</div><div>                PyErr_SetString(PyExc_RuntimeError, "Error in fixup (2)");</div>

<div>                Py_INCREF(Py_None);</div><div>                return Py_None;</div><div>            }</div><div>            act->val[3].type = MODFIXUP_ST;</div><div>        }</div><div>        if (i >= 2) {</div>

<div>            rval = fexport->fixup(&(act->val[2].u.data), 1);</div><div>            if (rval < 0) {</div><div>                PyErr_SetString(PyExc_RuntimeError, "Error in fixup (1)");</div><div>

                Py_INCREF(Py_None);</div><div>                return Py_None;</div><div>            }</div><div>            act->val[2].type = MODFIXUP_ST;</div><div>        }</div><div>        if (i == 1) {</div><div>

            rval = fexport->fixup(0, 0);</div><div>            if (rval < 0) {</div><div>                PyErr_SetString(PyExc_RuntimeError, "Error in fixup (0)");</div><div>                Py_INCREF(Py_None);</div>

<div>                return Py_None;</div><div>            }</div><div>        }</div><div>    }</div></div><div><br></div><div>I have very little experience with programming in C, and even less debugging with gdb or something similar, but from comparing this code with the way the Perl module does this, I couldn't see any obvious problems. I'm hoping someone with familiarity with the kamailio functions, such as fixup, might be able to identify the problem.</div>

<div><br></div><div>Judging from the exit code of app_python, my (uninformed) guess would be that there's an attempt to access or manipulate something in an out-of-scope memory address.</div></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Any suggestions would be greatly appreciated. I've written a quite large routing function in python and I'd like to avoid rewriting it in a different scripting language if possible.</div>

<div style="font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">The kamailio version I'm running is 4.0.4</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">

<br></div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Regards,</div><div style="font-family:arial,sans-serif;font-size:12.727272033691406px">Örn</div></div></div>