title: SIGHUP signal handler reset to default when using system() on embedded linux with busybox
body: <p>I am working on an embedded linux with busybox. As part of my application I have a rc.init script E80-startmyprog. That script is calling my program prog.</p>
  
  <pre class="lang-sh prettyprint-override"><code>trap "" HUP
  startmyprog &gt;${LOGFILE} 2&gt;&amp;1 &lt;/dev/null &amp;
  
  startmyprog() {
    prog
  }
  </code></pre>
  
  <p>In my program I can see that the signal handlers are set to ignore SIGHUP. I am checking that with</p>
  
  <pre class="lang-c prettyprint-override"><code>struct sigaction act;
  sigaction(1, NULL, &amp;act);
  printf("action %p\n", act.sa_sigaction);  // prints out 1 -&gt; SIG_IGN
  </code></pre>
  
  <p>Now at some time in my program I need to start another process, give it some input and check if it printed "yes" on stdout. I am using system to do that.</p>
  
  <pre class="lang-c prettyprint-override"><code>const int ret = system("[ `echo input | second_process` == yes ]");
  </code></pre>
  
  <p>Normal behavior is that <code>WIFEXITED(ret)</code> is true and that <code>WEXITSTATUS(ret)</code> is 0 or 1.</p>
  
  <p>But in some cases with unfortunate timing <code>WIFSIGNALED(ret)</code> is true and <code>WTERMSIG(ret)</code> is 1 (SIGHUP).</p>
  
  <p>Debugging shows that if I <code>execl("second_process", "second_process", (char*)NULL)</code> the signal handler state in second_process is set correctly to SIGHUP=ignore. But if I use <code>system</code>, then second_process has SIGHUP=default.</p>
  
  <p>My questions are:</p>
  
  <p>What is going on there? Who is resetting the SIGHUP signal handler at startup? Is it the shell? Is there a way to prevent that? (In the sh man page I have not seen a command line option that looks so.)</p>
  
  <p>I know I could do a workaround and setup a pipe, fork, exec second_process, write input to pipe, read output from pipe and parse output, but that is a lot of stuff compared to a system one liner and there is good chance that I will miss something and get it wrong.</p>