18 #include <system_error> 25 class ProcessImpl :
public Process
28 int spawn(
const std::string& new_exe_name,
const fs::path& argv0_path,
int& pid)
override 30 return mp::SpawnProcess(pid, [&](
int fd) {
31 fs::path path = argv0_path;
32 path.remove_filename();
33 path.append(new_exe_name);
34 return std::vector<std::string>{path.string(),
"-ipcfd",
strprintf(
"%i", fd)};
37 int waitSpawned(
int pid)
override {
return mp::WaitProcess(pid); }
38 bool checkSpawned(
int argc,
char* argv[],
int& fd)
override 43 if (argc != 3 || strcmp(argv[1],
"-ipcfd") != 0) {
53 throw std::runtime_error(
strprintf(
"Invalid -ipcfd number '%s'", argv[2]));
60 std::unique_ptr<Process>
MakeProcess() {
return std::make_unique<ProcessImpl>(); }
bool ParseInt32(const std::string &str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
std::unique_ptr< Process > MakeProcess()
Constructor for Process interface.