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
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 = CreateFileW(wstdin, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
It's the presence of
FILE_SHARE_WRITE for a read-only use of the file, which breaks other read-only uses.
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.