mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
Support: Don't call close again if we get EINTR
Most Unix-like operating systems guarantee that the file descriptor is closed after a call to close(2), even if close comes back with EINTR. For these systems, calling close _again_ will either do nothing or close some other file descriptor open(2)'d by another thread. (Linux) However, some operating systems do not have this behavior. They require at least another call to close(2) before guaranteeing that the descriptor is closed. (HP-UX) And some operating systems have an unpredictable blend of the two behaviors! (xnu) Avoid this disaster by blocking all signals before we call close(2). This ensures that a signal will not be delivered to the thread and close(2) will not give us back EINTR. We restore the signal mask once the operation is done. N.B. This isn't a problem on Windows, it doesn't have a notion of EINTR because signals always get delivered to dedicated signal handling threads. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219189 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -192,6 +192,15 @@ public:
|
||||
// components should not call this.
|
||||
static std::error_code FixupStandardFileDescriptors();
|
||||
|
||||
// This function safely closes a file descriptor. It is not safe to retry
|
||||
// close(2) when it returns with errno equivalent to EINTR; this is because
|
||||
// *nixen cannot agree if the file descriptor is, in fact, closed when this
|
||||
// occurs.
|
||||
//
|
||||
// N.B. Some operating systems, due to thread cancellation, cannot properly
|
||||
// guarantee that it will or will not be closed one way or the other!
|
||||
static std::error_code SafelyCloseFileDescriptor(int FD);
|
||||
|
||||
/// This function determines if the standard input is connected directly
|
||||
/// to a user's input (keyboard probably), rather than coming from a file
|
||||
/// or pipe.
|
||||
|
Reference in New Issue
Block a user