diff options
Diffstat (limited to 'runtime/exec_utils.cc')
-rw-r--r-- | runtime/exec_utils.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/runtime/exec_utils.cc b/runtime/exec_utils.cc index 7e04cced92..05a7cc6bdc 100644 --- a/runtime/exec_utils.cc +++ b/runtime/exec_utils.cc @@ -62,7 +62,9 @@ std::string ToCommandLine(const std::vector<std::string>& args) { // If there is a runtime (Runtime::Current != nullptr) then the subprocess is created with the // same environment that existed when the runtime was started. // Returns the process id of the child process on success, -1 otherwise. -pid_t ExecWithoutWait(const std::vector<std::string>& arg_vector, std::string* error_msg) { +pid_t ExecWithoutWait(const std::vector<std::string>& arg_vector, + bool new_process_group, + std::string* error_msg) { // Convert the args to char pointers. const char* program = arg_vector[0].c_str(); std::vector<char*> args; @@ -77,8 +79,9 @@ pid_t ExecWithoutWait(const std::vector<std::string>& arg_vector, std::string* e if (pid == 0) { // no allocation allowed between fork and exec - // change process groups, so we don't get reaped by ProcessManager - setpgid(0, 0); + if (new_process_group) { + setpgid(0, 0); + } // (b/30160149): protect subprocesses from modifications to LD_LIBRARY_PATH, etc. // Use the snapshot of the environment from the time the runtime was created. @@ -250,12 +253,18 @@ int ExecUtils::ExecAndReturnCode(const std::vector<std::string>& arg_vector, ExecResult ExecUtils::ExecAndReturnResult(const std::vector<std::string>& arg_vector, int timeout_sec, std::string* error_msg) const { - return ExecAndReturnResult(arg_vector, timeout_sec, ExecCallbacks(), /*stat=*/nullptr, error_msg); + return ExecAndReturnResult(arg_vector, + timeout_sec, + ExecCallbacks(), + /*new_process_group=*/false, + /*stat=*/nullptr, + error_msg); } ExecResult ExecUtils::ExecAndReturnResult(const std::vector<std::string>& arg_vector, int timeout_sec, const ExecCallbacks& callbacks, + bool new_process_group, /*out*/ ProcessStat* stat, /*out*/ std::string* error_msg) const { if (timeout_sec > INT_MAX / 1000) { @@ -264,7 +273,7 @@ ExecResult ExecUtils::ExecAndReturnResult(const std::vector<std::string>& arg_ve } // Start subprocess. - pid_t pid = ExecWithoutWait(arg_vector, error_msg); + pid_t pid = ExecWithoutWait(arg_vector, new_process_group, error_msg); if (pid == -1) { return {.status = ExecResult::kStartFailed}; } |