diff options
author | 2017-02-01 15:09:58 -0800 | |
---|---|---|
committer | 2017-02-01 15:51:42 -0800 | |
commit | 97c381e3ce34cd327c2ec35fa850bd0eaa9b697f (patch) | |
tree | 4a21b2db89c578cdb2908547547e0546748eec7f /runtime/utils.cc | |
parent | 3cb871ab1af47576959fd24a99d370381b8f193e (diff) |
Separate art::Exec from utils
The rest of utils.cc does not depend on art::Runtime. This separates
the part dependent on that class, so that including utils.cc in the
build does not require the entire Runtime. Another preparatory cleanup
to getting tools to build on Windows.
Bug: 22322814
Test: test-art
Change-Id: I194ff363fc2ab87e5311ecea6973a2d0fad2621d
Diffstat (limited to 'runtime/utils.cc')
-rw-r--r-- | runtime/utils.cc | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/runtime/utils.cc b/runtime/utils.cc index 80a427b1e7..6a20eaf9e0 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -929,74 +929,6 @@ std::string GetSystemImageFilename(const char* location, const InstructionSet is return filename; } -int ExecAndReturnCode(std::vector<std::string>& arg_vector, std::string* error_msg) { - const std::string command_line(android::base::Join(arg_vector, ' ')); - CHECK_GE(arg_vector.size(), 1U) << command_line; - - // Convert the args to char pointers. - const char* program = arg_vector[0].c_str(); - std::vector<char*> args; - for (size_t i = 0; i < arg_vector.size(); ++i) { - const std::string& arg = arg_vector[i]; - char* arg_str = const_cast<char*>(arg.c_str()); - CHECK(arg_str != nullptr) << i; - args.push_back(arg_str); - } - args.push_back(nullptr); - - // fork and exec - pid_t pid = fork(); - if (pid == 0) { - // no allocation allowed between fork and exec - - // change process groups, so we don't get reaped by ProcessManager - 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. - char** envp = (Runtime::Current() == nullptr) ? nullptr : Runtime::Current()->GetEnvSnapshot(); - if (envp == nullptr) { - execv(program, &args[0]); - } else { - execve(program, &args[0], envp); - } - PLOG(ERROR) << "Failed to execve(" << command_line << ")"; - // _exit to avoid atexit handlers in child. - _exit(1); - } else { - if (pid == -1) { - *error_msg = StringPrintf("Failed to execv(%s) because fork failed: %s", - command_line.c_str(), strerror(errno)); - return -1; - } - - // wait for subprocess to finish - int status = -1; - pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); - if (got_pid != pid) { - *error_msg = StringPrintf("Failed after fork for execv(%s) because waitpid failed: " - "wanted %d, got %d: %s", - command_line.c_str(), pid, got_pid, strerror(errno)); - return -1; - } - if (WIFEXITED(status)) { - return WEXITSTATUS(status); - } - return -1; - } -} - -bool Exec(std::vector<std::string>& arg_vector, std::string* error_msg) { - int status = ExecAndReturnCode(arg_vector, error_msg); - if (status != 0) { - const std::string command_line(android::base::Join(arg_vector, ' ')); - *error_msg = StringPrintf("Failed execv(%s) because non-0 exit status", - command_line.c_str()); - return false; - } - return true; -} - bool FileExists(const std::string& filename) { struct stat buffer; return stat(filename.c_str(), &buffer) == 0; |