CTest exposes log file descriptor to test process
When running some unit tests under Valgrind, I noticed the report of fd 3 being leaked. Further inspection revealed it to be Testing/Temporary/LastTest.log.tmp
.
I did some digging and found that this is opened by: https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmCTest.cxx#L815
which calls into: https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmGeneratedFileStream.cxx#L55
Surely that log file has to be closed before executing the test program, but I'm not that well versed in portable C++ code and couldn't figure out the correct place to do it. On my platform, Stream
appears to be derived from basic_ofstream
. For that class, I couldn't figure out how to set O_CLOEXEC
when opening the file from cmGeneratedFileStreamBase
nor how to retrieve the underlying file descriptor to set the flag via fcntl()
(I'm not even sure that would be an acceptable option given how portable CTest is).