<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hello,</p>
    <br>
    <div class="moz-cite-prefix">On 27.04.17 04:18, Cody Herzog wrote:<br>
    </div>
    <blockquote
      cite="mid:2AF4E0DB5D20734E8939C5EF204ACBAC0143A6DCE7@ITHMail2.ith.local"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="Generator" content="Microsoft Word 15 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal">Hello.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I'm running Kamailio 4.3.5 on Ubuntu Server
          14.04.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I just started using the app_python module
          together with the OpenTok Python SDK, described here:<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><a moz-do-not-send="true"
            href="https://tokbox.com/developer/sdks/python/">https://tokbox.com/developer/sdks/python/</a><o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">My basic Python test script works fine, but
          when I add an import statement in the Python script to bring
          in a package from the OpenTok Python SDK, Kamailio terminates
          right after launch with the following log message:<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">"terminating due to SIGCHLD"<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I was surprised to not find any extra log
          messages indicating which child process was causing the
          signal.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I hacked the code in the handle_sigs()
          function in main.c.c to NOT terminate in response to SIGCHLD,
          and was surprised to see that my Python script was working
          fine, and was able to properly use the OpenTok Python SDK.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I then started adding more debugging log
          statements and discovered that the call to waitpid() was
          returning 0, which apparently indicates that no child process
          has changed state.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">It's very strange, because it seems that
          SIGCHLD is being sent and handled, but waitpid() is indicating
          that no child process has changed state.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I'm not sure if that is valid situation
          which needs to be handled. Perhaps SIGCHLD is sometimes sent
          for spurious or harmless reasons which should be ignored, and
          not result in total Kamailio termination.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">My current workaround is to NOT terminate
          when SIGCHLD is received and waitpid() indicates that no child
          process has changed state. In other words, I only terminate
          when the waitpid() while() loop has been entered at least once
          due to a return value greater than 0.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">Does that seem like a change that might
          make sense in the master branch going forward, or does it seem
          dangerous somehow?<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal">I'm not sure if this is helpful, but the
          waitid() system call (available since Linux 2.6.9) provides
          more precise control over which child state changes to wait
          for.<o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
        <p class="MsoNormal"><a moz-do-not-send="true"
            href="http://manpages.ubuntu.com/manpages/trusty/man2/wait.2.html">http://manpages.ubuntu.com/manpages/trusty/man2/wait.2.html</a><o:p></o:p></p>
        <p class="MsoNormal"><o:p> </o:p></p>
      </div>
    </blockquote>
    this can happen because your python script (or the libs used there)
    creates new processes and they terminate. Kamailio has a strict
    policy on watching the children and terminating if one disappears.<br>
    <br>
    I think we can relax that based on your suggestion. Can you make a
    pull request on github.com/kamailio/kamailio with your proposed
    changes?<br>
    <br>
    Ideally with a new parameter to control this behaviour, but don't
    worry if it is not straightforward for you to look at flex/bison
    files, I will do it on top of your patch.<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a>
Kamailio Advanced Training - May 22-24 (USA) - <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
Kamailio World Conference - May 8-10, 2017 - <a class="moz-txt-link-abbreviated" href="http://www.kamailioworld.com">www.kamailioworld.com</a></pre>
  </body>
</html>