title: system() keeps returning 127
body: <p>I am developing a shared-library <code>L</code> which is used by an other system service <code>S</code>. In my program I need to call a small program <code>P</code>, which uses Oracle shared libraries.</p>
  
  <p>The small program <code>P</code> is packaged and installed correctly, and the environment variables, such as <code>PATH</code>,<code>LD_LIBRARY_PATH</code> and <code>ORACLE_HOME</code> are set correctly. I can run <code>P</code> on command line without any problem.</p>
  
  <p>But when service <code>S</code> call my library <code>L</code> which runs the small program <code>P</code> via <code>system()</code>, it gives me a return code <code>127</code>. I've googled, people says it's a <code>command not found</code> error, probably a <code>PATH</code> issue, so I've tried with absolute path like the following</p>
  
  <pre><code>int status = system("/usr/bin/myprog --args");
  if (status &lt; 0) { ... }
  ret = WEXITSTATUS(status);
  </code></pre>
  
  <p><code>ret</code> still equals <code>127</code>.</p>
  
  <p>Any idea please ? Thank you.</p>
  
  <p><strong>Update</strong>
  It turns out that the service <code>S</code> is launched via command <code>daemon</code>, in its <code>init.d</code> script, I have found the following line:</p>
  
  <pre><code>daemon /usr/bin/myserv
  </code></pre>
  
  <p>if I <code>export</code> explicitly all my environment variables (<code>PATH</code>, <code>ORACLE_HOME</code> and <code>LD_LIBRARY_PATH</code>), it works. I don't know if <code>daemon</code> eliminates my environment variables.</p>