[llvm-commits] [llvm] r78128 - /llvm/trunk/lib/System/Unix/Program.inc

Dan Gohman gohman at apple.com
Tue Aug 4 17:09:29 PDT 2009


Author: djg
Date: Tue Aug  4 19:09:12 2009
New Revision: 78128

URL: http://llvm.org/viewvc/llvm-project?rev=78128&view=rev
Log:
Use _exit rather than exit in the child process after a failed exec.
Add a comment explaining why.

Modified:
    llvm/trunk/lib/System/Unix/Program.inc

Modified: llvm/trunk/lib/System/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Unix/Program.inc?rev=78128&r1=78127&r2=78128&view=diff

==============================================================================
--- llvm/trunk/lib/System/Unix/Program.inc (original)
+++ llvm/trunk/lib/System/Unix/Program.inc Tue Aug  4 19:09:12 2009
@@ -200,9 +200,13 @@
         execve(path.c_str(), (char**)args, (char**)envp);
       else
         execv(path.c_str(), (char**)args);
-      // If the execve() failed, we should exit and let the parent pick up
-      // our non-zero exit status.
-      exit(errno == ENOENT ? 127 : 126);
+      // If the execve() failed, we should exit. Follow Unix protocol and
+      // return 127 if the executable was not found, and 126 otherwise.
+      // Use _exit rather than exit so that atexit functions and static
+      // object destructors cloned from the parent process aren't
+      // redundantly run, and so that any data buffered in stdio buffers
+      // cloned from the parent aren't redundantly written out.
+      _exit(errno == ENOENT ? 127 : 126);
     }
 
     // Parent process: Break out of the switch to do our processing.





More information about the llvm-commits mailing list