in util/process_wrapper/system_posix.cc [64:98]
bool WriteToFile(const System::StrType &stdout_file) {
CloseWriteEnd();
constexpr size_t kBufferSize = 4096;
char buffer[kBufferSize];
int output_file_desc =
open(stdout_file.c_str(), O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (output_file_desc == -1) {
std::cerr << "process wrapper error: failed to open redirection file: "
<< std::strerror(errno) << ".\n";
return false;
}
while (1) {
ssize_t read_bytes = read(ReadEndDesc(), buffer, kBufferSize);
if (read_bytes < 0) {
std::cerr
<< "process wrapper error: failed to read child process output: "
<< std::strerror(errno) << ".\n";
return false;
} else if (read_bytes == 0) {
break;
}
ssize_t written_bytes = write(output_file_desc, buffer, read_bytes);
if (written_bytes < 0 || written_bytes != read_bytes) {
std::cerr << "process wrapper error: failed to write to ouput file: "
<< std::strerror(errno) << ".\n";
return false;
}
}
CloseReadEnd();
close(output_file_desc);
return true;
}