title: C - Program fails to get file descriptor only when running with GDB
body: <p>I'm not an expert C programmer. I'm having trouble debugging a program using GDB. (The bug I am trying to fix is unrelated to the problem I am asking about here.) My problem is that the program runs fine when I run the binary directly from a shell, but the program crashes when I run it using GDB.</p>
  
  <p>Here is some information about the program which may be useful: it is a 20+ year old piece of database software, originally written for Solaris (I think) but since ported to Linux, which is setuid (but not to root, thank god).</p>
  
  <p>The program crashes in GDB when trying to open a file for writing. Using GDB, I was able to determine that crash occurs because the following system call fails:</p>
  
  <pre><code>fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644);
  </code></pre>
  
  <p>For clarification: <code>path</code> is the path to a lockfile which <em>should not</em> exist. If the lock file exists, then the program shuts down cleanly before it even reaches this system call.</p>
  
  <p>I do not understand why this system call would fail, since 1) The user this program runs as has rwx permissions on the directory containing <code>path</code> (I have verified this by examining the value of the variable stored in <code>path</code>), and 2) the program successfully opens the file for writing when I am not using GDB to debug it.</p>
  
  <p>Are there any reasons why I cannot </p>