| 42 | } |
| 43 | int waitSpawned(int pid) override { return mp::WaitProcess(pid); } |
| 44 | bool checkSpawned(int argc, char* argv[], int& fd) override |
| 45 | { |
| 46 | // If this process was not started with a single -ipcfd argument, it is |
| 47 | // not a process spawned by the spawn() call above, so return false and |
| 48 | // do not try to serve requests. |
| 49 | if (argc != 3 || strcmp(argv[1], "-ipcfd") != 0) { |
| 50 | return false; |
| 51 | } |
| 52 | // If a single -ipcfd argument was provided, return true and get the |
| 53 | // file descriptor so Protocol::serve() can be called to handle |
| 54 | // requests from the parent process. The -ipcfd argument is not valid |
| 55 | // in combination with other arguments because the parent process |
| 56 | // should be able to control the child process through the IPC protocol |
| 57 | // without passing information out of band. |
| 58 | const auto maybe_fd{ToIntegral<int32_t>(argv[2])}; |
| 59 | if (!maybe_fd) { |
| 60 | throw std::runtime_error(strprintf("Invalid -ipcfd number '%s'", argv[2])); |
| 61 | } |
| 62 | fd = *maybe_fd; |
| 63 | return true; |
| 64 | } |
| 65 | int connect(const fs::path& data_dir, |
| 66 | const std::string& dest_exe_name, |
| 67 | std::string& address) override; |