Push all debug output into stderr.
This leaves stdout empty for reporting a list of output files.
Bug: 135293952
Test: Run "fetch_cvd >stdout 2>stderr" and check stdout and stderr.
Change-Id: Ic5b38a12182fac202faf6a93883f5e8e80dc8227
diff --git a/host/commands/fetcher/fetch_cvd.cc b/host/commands/fetcher/fetch_cvd.cc
index 9fdb469..5f60700 100644
--- a/host/commands/fetcher/fetch_cvd.cc
+++ b/host/commands/fetcher/fetch_cvd.cc
@@ -149,11 +149,18 @@
return false;
}
- if (cvd::execute({"/bin/tar", "xvf", local_path, "-C", target_directory}) != 0) {
+ cvd::Command tar_cmd("/bin/tar");
+ tar_cmd.AddParameter("xvf");
+ tar_cmd.AddParameter(local_path);
+ tar_cmd.AddParameter("-C");
+ tar_cmd.AddParameter(target_directory);
+ tar_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ if (tar_cmd.Start().Wait() != 0) {
LOG(FATAL) << "Could not extract " << local_path;
return false;
}
- if (unlink(HOST_TOOLS.c_str()) != 0) {
+ if (unlink(local_path.c_str()) != 0) {
LOG(ERROR) << "Could not delete " << local_path;
}
return true;
@@ -161,7 +168,13 @@
bool desparse(const std::string& file) {
LOG(INFO) << "Unsparsing " << file;
- if (cvd::execute({"/bin/dd", "if=" + file, "of=" + file, "conv=notrunc"}) != 0) {
+ cvd::Command dd_cmd("/bin/dd");
+ dd_cmd.AddParameter("if=", file);
+ dd_cmd.AddParameter("of=", file);
+ dd_cmd.AddParameter("conv=notrunc");
+ dd_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ if (dd_cmd.Start().Wait() != 0) {
LOG(ERROR) << "Could not unsparse " << file;
return false;
}
@@ -193,9 +206,17 @@
LOG(FATAL) << "Could not create " << otatools_dir;
return false;
}
- auto bsdtar_out = cvd::execute(
- {"/usr/bin/bsdtar", "-x", "-v", "-C", otatools_dir, "-f", local_path, "-S"});
- if (bsdtar_out != 0) {
+ cvd::Command bsdtar_cmd("/usr/bin/bsdtar");
+ bsdtar_cmd.AddParameter("-x");
+ bsdtar_cmd.AddParameter("-v");
+ bsdtar_cmd.AddParameter("-C");
+ bsdtar_cmd.AddParameter(otatools_dir);
+ bsdtar_cmd.AddParameter("-f");
+ bsdtar_cmd.AddParameter(local_path);
+ bsdtar_cmd.AddParameter("-S");
+ bsdtar_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ if (bsdtar_cmd.Start().Wait() != 0) {
LOG(FATAL) << "Could not extract " << local_path;
return false;
}
@@ -316,7 +337,10 @@
// 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"});
+ cvd::Command stop_cmd("bin/stop_cvd");
+ stop_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ stop_cmd.Start().Wait();
// gflags::ParseCommandLineFlags will remove fetch_cvd's flags from this.
// This depends the remove_flags argument (3rd) is "true".
diff --git a/host/commands/fetcher/install_zip.cc b/host/commands/fetcher/install_zip.cc
index ad7f08c..b5b8f81 100644
--- a/host/commands/fetcher/install_zip.cc
+++ b/host/commands/fetcher/install_zip.cc
@@ -42,18 +42,20 @@
bool ExtractImages(const std::string& archive,
const std::string& target_directory,
const std::vector<std::string>& images) {
- std::vector<std::string> bsdtar_cmd = {
- "/usr/bin/bsdtar",
- "-x",
- "-v",
- "-C", target_directory,
- "-f", archive,
- "-S",
- };
+ cvd::Command bsdtar_cmd("/usr/bin/bsdtar");
+ bsdtar_cmd.AddParameter("-x");
+ bsdtar_cmd.AddParameter("-v");
+ bsdtar_cmd.AddParameter("-C");
+ bsdtar_cmd.AddParameter(target_directory);
+ bsdtar_cmd.AddParameter("-f");
+ bsdtar_cmd.AddParameter(archive);
+ bsdtar_cmd.AddParameter("-S");
for (const auto& img : images) {
- bsdtar_cmd.push_back(img);
+ bsdtar_cmd.AddParameter(img);
}
- auto bsdtar_ret = cvd::execute(bsdtar_cmd);
+ bsdtar_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ auto bsdtar_ret = bsdtar_cmd.Start().Wait();
if (bsdtar_ret != 0) {
LOG(ERROR) << "Unable to extract images. bsdtar returned " << bsdtar_ret;
return false;
@@ -80,8 +82,12 @@
continue;
}
std::string inflated_file = extracted_file + ".inflated";
- auto simg_ret = cvd::execute({"/usr/bin/simg2img", extracted_file, inflated_file});
- if (simg_ret != 0) {
+ cvd::Command simg_cmd("/usr/bin/simg2img");
+ simg_cmd.AddParameter(extracted_file);
+ simg_cmd.AddParameter(inflated_file);
+ simg_cmd.RedirectStdIO(cvd::Subprocess::StdIOChannel::kStdOut,
+ cvd::Subprocess::StdIOChannel::kStdErr);
+ if (simg_cmd.Start().Wait() != 0) {
LOG(ERROR) << "Unable to run simg2img on " << file;
extraction_success = false;
continue;