summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Schuffelen <schuffelen@google.com>2019-08-09 16:34:40 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-09 16:34:40 -0700
commitc4a92ee0fba1683022ea6d92164867196fc6053f (patch)
tree0462075b90993e3e6d053ca732b71f01ad6af80e
parent7baf0091e731b6bd64d51dadf303230d51591b8a (diff)
parente6419cef7f038fdc2f226b6bcfbf2859c33ee0b7 (diff)
downloadcuttlefish_common-c4a92ee0fba1683022ea6d92164867196fc6053f.tar.gz
Merge "Enter second-stage launch from first-stage launch."
am: e6419cef7f Change-Id: Ib318bad82ab770b6ae7155b22ded4f2559427fc0
-rw-r--r--host/commands/fetcher/main.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/host/commands/fetcher/main.cc b/host/commands/fetcher/main.cc
index 7b460e33..3e555e56 100644
--- a/host/commands/fetcher/main.cc
+++ b/host/commands/fetcher/main.cc
@@ -38,6 +38,7 @@ DEFINE_string(system_image_build_id, "", "Alternate build for the system "
"image");
DEFINE_string(directory, cvd::CurrentDirectory(), "Target directory to fetch "
"files into");
+DEFINE_bool(run_next_stage, false, "Continue running the device through the next stage.");
namespace {
@@ -167,4 +168,35 @@ int main(int argc, char** argv) {
}
}
curl_global_cleanup();
+
+ if (!FLAGS_run_next_stage) {
+ return 0;
+ }
+
+ if (chdir(target_dir.c_str()) != 0) {
+ int error_num = errno;
+ LOG(FATAL) << "Could not change directory to \"" << target_dir << "\"."
+ << "errno was " << error_num << " \"" << strerror(error_num) << "\"";
+ }
+
+ // Ignore return code. We want to make sure there is no running instance,
+ // and stop_cvd will exit with an error code if there is already no running instance.
+ cvd::execute({"bin/stop_cvd"});
+
+ // gflags::ParseCommandLineFlags will remove fetch_cvd's flags from this.
+ // This depends the remove_flags argument (3rd) is "true".
+
+ // TODO(b/139199114): Go into assemble_cvd when the interface is stable and implemented.
+
+ std::string next_stage = "bin/launch_cvd";
+ std::vector<const char*> next_stage_argv = {"launch_cvd"};
+ LOG(INFO) << "Running " << next_stage;
+ for (int i = 1; i < argc; i++) {
+ LOG(INFO) << argv[i];
+ next_stage_argv.push_back(argv[i]);
+ }
+ next_stage_argv.push_back(nullptr);
+ execv(next_stage.c_str(), const_cast<char* const*>(next_stage_argv.data()));
+ int error = errno;
+ LOG(FATAL) << "execv returned with errno " << error << ":" << strerror(error);
}