| 113 | } |
| 114 | |
| 115 | void SubProcess::SetProgram(const string& file, |
| 116 | const std::vector<string>& argv) { |
| 117 | mutex_lock procLock(proc_mu_); |
| 118 | mutex_lock dataLock(data_mu_); |
| 119 | if (running_) { |
| 120 | LOG(FATAL) << "SetProgram called after the process was started."; |
| 121 | return; |
| 122 | } |
| 123 | |
| 124 | FreeArgs(); |
| 125 | exec_path_ = strdup(file.c_str()); |
| 126 | if (exec_path_ == nullptr) { |
| 127 | LOG(FATAL) << "SetProgram failed to allocate file string."; |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | int argc = argv.size(); |
| 132 | exec_argv_ = new char*[argc + 1]; |
| 133 | for (int i = 0; i < argc; i++) { |
| 134 | exec_argv_[i] = strdup(argv[i].c_str()); |
| 135 | if (exec_argv_[i] == nullptr) { |
| 136 | LOG(FATAL) << "SetProgram failed to allocate command argument."; |
| 137 | return; |
| 138 | } |
| 139 | } |
| 140 | exec_argv_[argc] = nullptr; |
| 141 | } |
| 142 | |
| 143 | void SubProcess::SetChannelAction(Channel chan, ChannelAction action) { |
| 144 | mutex_lock procLock(proc_mu_); |