Use _exit rather than exit in the child process after a failed exec.
authorDan Gohman <gohman@apple.com>
Wed, 5 Aug 2009 00:09:12 +0000 (00:09 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 5 Aug 2009 00:09:12 +0000 (00:09 +0000)
Add a comment explaining why.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78128 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Unix/Program.inc

index 4814228e138c98e025bae6067811267b4bd27977..43a3e7f28339318ca3ad9749cf348e3833153843 100644 (file)
@@ -200,9 +200,13 @@ Program::Execute(const Path& path,
         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.