aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Unix/Program.inc
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-05 00:09:12 +0000
committerDan Gohman <gohman@apple.com>2009-08-05 00:09:12 +0000
commita629b695c44a64efa9e978aa0467325cdf6ff874 (patch)
tree9d9ee0b820f9a040e97825aa460d2e68be96fa0b /lib/System/Unix/Program.inc
parent76efb34b99a7a49127a2877e45cf873e5b5fbcad (diff)
downloadexternal_llvm-a629b695c44a64efa9e978aa0467325cdf6ff874.zip
external_llvm-a629b695c44a64efa9e978aa0467325cdf6ff874.tar.gz
external_llvm-a629b695c44a64efa9e978aa0467325cdf6ff874.tar.bz2
Use _exit rather than exit in the child process after a failed exec.
Add a comment explaining why. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix/Program.inc')
-rw-r--r--lib/System/Unix/Program.inc10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/System/Unix/Program.inc b/lib/System/Unix/Program.inc
index 4814228..43a3e7f 100644
--- a/lib/System/Unix/Program.inc
+++ b/lib/System/Unix/Program.inc
@@ -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.