| 51 | } |
| 52 | |
| 53 | bool cmProcess::StartProcess(uv_loop_t& loop, std::vector<size_t>* affinity) |
| 54 | { |
| 55 | this->ProcessState = cmProcess::State::Error; |
| 56 | if (this->Command.empty()) { |
| 57 | return false; |
| 58 | } |
| 59 | this->StartTime = std::chrono::steady_clock::now(); |
| 60 | this->SystemStartTime = std::chrono::system_clock::now(); |
| 61 | this->ProcessArgs.clear(); |
| 62 | // put the command as arg0 |
| 63 | this->ProcessArgs.push_back(this->Command.c_str()); |
| 64 | // now put the command arguments in |
| 65 | for (std::string const& arg : this->Arguments) { |
| 66 | this->ProcessArgs.push_back(arg.c_str()); |
| 67 | } |
| 68 | this->ProcessArgs.push_back(nullptr); // null terminate the list |
| 69 | |
| 70 | cm::uv_timer_ptr timer; |
| 71 | int status = timer.init(loop, this); |
| 72 | if (status != 0) { |
| 73 | cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, |
| 74 | "Error initializing timer: " << uv_strerror(status) |
| 75 | << std::endl); |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | cm::uv_pipe_ptr pipe_writer; |
| 80 | cm::uv_pipe_ptr pipe_reader; |
| 81 | |
| 82 | pipe_writer.init(loop, 0); |
| 83 | pipe_reader.init(loop, 0, this); |
| 84 | |
| 85 | int fds[2] = { -1, -1 }; |
| 86 | status = cmGetPipes(fds); |
| 87 | if (status != 0) { |
| 88 | cmCTestLog(this->Runner->GetCTest(), ERROR_MESSAGE, |
| 89 | "Error initializing pipe: " << uv_strerror(status) |
| 90 | << std::endl); |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | uv_pipe_open(pipe_reader, fds[0]); |
| 95 | uv_pipe_open(pipe_writer, fds[1]); |
| 96 | |
| 97 | uv_stdio_container_t stdio[3]; |
| 98 | stdio[0].flags = UV_INHERIT_FD; |
| 99 | stdio[0].data.fd = 0; |
| 100 | stdio[1].flags = UV_INHERIT_STREAM; |
| 101 | stdio[1].data.stream = pipe_writer; |
| 102 | stdio[2] = stdio[1]; |
| 103 | |
| 104 | uv_process_options_t options = uv_process_options_t(); |
| 105 | options.file = this->Command.data(); |
| 106 | options.args = const_cast<char**>(this->ProcessArgs.data()); |
| 107 | options.stdio_count = 3; // in, out and err |
| 108 | options.exit_cb = &cmProcess::OnExitCB; |
| 109 | options.stdio = stdio; |
| 110 | #if UV_VERSION_MAJOR > 1 || !defined(CMAKE_USE_SYSTEM_LIBUV) |