Support: Add a utility to remap std{in,out,err} to /dev/null if closed

It's possible to start a program with one (or all) of the standard file
descriptors closed.  Subsequent open system calls will give the program
a low-numbered file descriptor.

This is problematic because we may believe we are writing to standard
out instead of a file.

Introduce Process::FixupStandardFileDescriptors, a helper function to
remap standard file descriptors to /dev/null if they were closed before
the program started.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2014-10-06 23:16:18 +00:00
parent 5b8cd15092
commit 3ba3a4ccfd
3 changed files with 69 additions and 0 deletions

View File

@@ -273,6 +273,10 @@ Process::GetArgumentVector(SmallVectorImpl<const char *> &Args,
return ec;
}
std::error_code Process::FixupStandardFileDescriptors() {
return std::error_code();
}
bool Process::StandardInIsUserInput() {
return FileDescriptorIsDisplayed(0);
}