MCPcopy Create free account
hub / github.com/MrNeRF/LichtFeld-Studio / start

Method start

src/python/subprocess.cpp:30–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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)

Callers

nothing calls this directly

Calls 7

build_win32_cmdlineFunction · 0.85
utf8_to_pathFunction · 0.85
c_strMethod · 0.80
utf8_to_wstringFunction · 0.50
push_backMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected