execute_command: File open mode for pipe leads to poor interoperability (other readers can't open file read-only)
Context: this ticket
This codebase ultimately calls CreateFileW
to open a file on Windows: here
However, the unit tests fail when run from ctest/cmake in parallel. They are run from execute_process
here which is driven by a helper which is used like this.
The tests only fail when run in parallel with tests opening stdin using the same input file. It looks like this code in cmake is at fault: kwsys/ProcessWin32.c:
cp->PipeChildStd[0] =
CreateFileW(wstdin, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
It's the presence of GENERIC_WRITE
/FILE_SHARE_WRITE
for a read-only use of the file, which breaks other read-only uses.
Looking at KWSys.git, it looks like it's been this way from 396f866c to ed7f53e0.
I can see from the commit message that this was done originally to allow simultaneous writing, so this is really a heads up that this causes problems of its own. Looking at the Windows file documentation I'm unsure what a useful general solution would be. This seems entirely Windows-specific; Unix isn't a problem in this respect, it's solely down to the Windows file access semantics being rather restrictive.