Merge topic 'execute_process-OUTPUT_FILE-cloexec'
60af429c5d
execute_process: Restore CLOEXEC on OUTPUT_FILE and ERROR_FILE descriptors
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Bertrand Bellenot <bertrand.bellenot@cern.ch>
Merge-request: !10014
This commit is contained in:
commit
ee5a6f3aec
@ -18,6 +18,12 @@
|
||||
|
||||
#include <cm3p/uv.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <fcntl.h>
|
||||
|
||||
# include "cm_fileno.hxx"
|
||||
#endif
|
||||
|
||||
#include "cmArgumentParser.h"
|
||||
#include "cmExecutionStatus.h"
|
||||
#include "cmList.h"
|
||||
@ -37,6 +43,20 @@ bool cmExecuteProcessCommandIsWhitespace(char c)
|
||||
return (cmIsSpace(c) || c == '\n' || c == '\r');
|
||||
}
|
||||
|
||||
FILE* FopenCLOEXEC(std::string const& path, const char* mode)
|
||||
{
|
||||
FILE* f = cmsys::SystemTools::Fopen(path, mode);
|
||||
#ifndef _WIN32
|
||||
if (f) {
|
||||
if (fcntl(cm_fileno(f), F_SETFD, FD_CLOEXEC) < 0) {
|
||||
fclose(f);
|
||||
f = nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return f;
|
||||
}
|
||||
|
||||
void cmExecuteProcessCommandFixText(std::vector<char>& output,
|
||||
bool strip_trailing_whitespace);
|
||||
void cmExecuteProcessCommandAppend(std::vector<char>& output, const char* data,
|
||||
@ -180,7 +200,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
// Check the output variables.
|
||||
std::unique_ptr<FILE, int (*)(FILE*)> inputFile(nullptr, fclose);
|
||||
if (!inputFilename.empty()) {
|
||||
inputFile.reset(cmsys::SystemTools::Fopen(inputFilename, "rb"));
|
||||
inputFile.reset(FopenCLOEXEC(inputFilename, "rb"));
|
||||
if (inputFile) {
|
||||
builder.SetExternalStream(cmUVProcessChainBuilder::Stream_INPUT,
|
||||
inputFile.get());
|
||||
@ -191,7 +211,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
|
||||
std::unique_ptr<FILE, int (*)(FILE*)> outputFile(nullptr, fclose);
|
||||
if (!outputFilename.empty()) {
|
||||
outputFile.reset(cmsys::SystemTools::Fopen(outputFilename, "wb"));
|
||||
outputFile.reset(FopenCLOEXEC(outputFilename, "wb"));
|
||||
if (outputFile) {
|
||||
builder.SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT,
|
||||
outputFile.get());
|
||||
@ -213,7 +233,7 @@ bool cmExecuteProcessCommand(std::vector<std::string> const& args,
|
||||
outputFile.get());
|
||||
}
|
||||
} else {
|
||||
errorFile.reset(cmsys::SystemTools::Fopen(errorFilename, "wb"));
|
||||
errorFile.reset(FopenCLOEXEC(errorFilename, "wb"));
|
||||
if (errorFile) {
|
||||
builder.SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR,
|
||||
errorFile.get());
|
||||
|
Loading…
Reference in New Issue
Block a user