| 28 | #ifndef _WIN32 |
| 29 | |
| 30 | bool SubProcess::start(const std::string& program, const std::vector<std::string>& args) { |
| 31 | kill(); |
| 32 | |
| 33 | constexpr unsigned short PTY_COLS = 120; |
| 34 | constexpr unsigned short PTY_ROWS = 24; |
| 35 | struct winsize ws = {}; |
| 36 | ws.ws_col = PTY_COLS; |
| 37 | ws.ws_row = PTY_ROWS; |
| 38 | |
| 39 | pid_ = forkpty(&stdout_fd_, nullptr, nullptr, &ws); |
| 40 | if (pid_ == -1) { |
| 41 | LOG_ERROR("forkpty() failed: {}", strerror(errno)); |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | if (pid_ == 0) { |
| 46 | setenv("UV_HTTP_TIMEOUT", "300", 1); |
| 47 | setenv("TERM", "xterm-256color", 1); |
| 48 | |
| 49 | std::vector<const char*> argv; |
| 50 | argv.push_back(program.c_str()); |
| 51 | for (const auto& arg : args) |
| 52 | argv.push_back(arg.c_str()); |
| 53 | argv.push_back(nullptr); |
| 54 | |
| 55 | execvp(program.c_str(), const_cast<char* const*>(argv.data())); |
| 56 | _exit(127); |
| 57 | } |
| 58 | |
| 59 | const int flags = fcntl(stdout_fd_, F_GETFL, 0); |
| 60 | fcntl(stdout_fd_, F_SETFL, flags | O_NONBLOCK); |
| 61 | |
| 62 | LOG_INFO("Subprocess started: {} (pid {})", program, pid_); |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | ssize_t SubProcess::read(char* buf, size_t len) { |
| 67 | if (stdout_fd_ < 0) |
nothing calls this directly
no test coverage detected