diff options
author | Brad King <brad.king@kitware.com> | 2008-08-20 13:57:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-08-20 13:57:09 (GMT) |
commit | 07665de0386e3ee572e95f999d6b516391331e26 (patch) | |
tree | d3fe32f553f9f3d54cb8388d1a2dc8bfcdf3550b /Source/kwsys/ProcessUNIX.c | |
parent | 9f1c7bdbaa6c33ca911cc30279544b95fccfaaa4 (diff) | |
download | CMake-07665de0386e3ee572e95f999d6b516391331e26.zip CMake-07665de0386e3ee572e95f999d6b516391331e26.tar.gz CMake-07665de0386e3ee572e95f999d6b516391331e26.tar.bz2 |
BUG: Handle case when select() lies
According to "man select" on Linux it is possible that select() lies
about data being ready on a pipe in some subtle cases. We deal with
this by switching to non-blocking i/o and checking for EAGAIN. See
issue #7180.
Diffstat (limited to 'Source/kwsys/ProcessUNIX.c')
-rw-r--r-- | Source/kwsys/ProcessUNIX.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index becd004..515bceb 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -770,14 +770,14 @@ void kwsysProcess_Execute(kwsysProcess* cp) return; } -#if !KWSYSPE_USE_SELECT + /* Set to non-blocking in case select lies, or for the polling + implementation. */ if(!kwsysProcessSetNonBlocking(p[0])) { kwsysProcessCleanup(cp, 1); kwsysProcessCleanupDescriptor(&si.StdErr); return; } -#endif } /* Replace the stderr pipe with a file if requested. In this case @@ -830,14 +830,12 @@ void kwsysProcess_Execute(kwsysProcess* cp) failed = 1; } -#if !KWSYSPE_USE_SELECT - /* Set the output pipe of the last process to be non-blocking so - we can poll it. */ - if(i == cp->NumberOfCommands-1 && !kwsysProcessSetNonBlocking(readEnd)) + /* Set the output pipe of the last process to be non-blocking in + case select lies, or for the polling implementation. */ + if(i == (cp->NumberOfCommands-1) && !kwsysProcessSetNonBlocking(readEnd)) { failed = 1; } -#endif if(failed) { @@ -1057,6 +1055,11 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length, return 1; } } + else if(n < 0 && errno == EAGAIN) + { + /* No data are really ready. The select call lied. See the + "man select" page on Linux for cases when this occurs. */ + } else { /* We are done reading from this pipe. */ |