Skip to content

Commit 7e03a58

Browse files
committed
cvd: Fallback to --help when --helpxml is unsupported in status fetcher
Older guest host tools (e.g. Android T / tm-qpr-dev / SDK 32) do not support --helpxml and abort with SIGABRT when it is passed, resulting in empty output and ParseGflagsXmlHelp failure. Fall back to --help if ParseGflagsXmlHelp fails. Bug: b/546992730
1 parent b63bde5 commit 7e03a58

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/instances/status_fetcher.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,33 @@ Result<Json::Value> FetchInstanceStatus(LocalInstance& instance,
115115
std::string stdout_str, stderr_str;
116116
RunWithManagedStdio(std::move(help_cmd), nullptr, &stdout_str, &stderr_str);
117117

118-
std::vector<GflagDescription> internal_flags =
119-
CF_EXPECT(ParseGflagsXmlHelp(stdout_str));
120-
bool has_print = std::any_of(
121-
internal_flags.begin(), internal_flags.end(),
122-
[](const GflagDescription& desc) { return desc.name == "print"; });
118+
bool has_print = false;
119+
auto internal_flags = ParseGflagsXmlHelp(stdout_str);
120+
if (internal_flags.ok()) {
121+
has_print = std::any_of(
122+
internal_flags->begin(), internal_flags->end(),
123+
[](const GflagDescription& desc) { return desc.name == "print"; });
124+
} else {
125+
LOG(INFO) << bin
126+
<< " does not support --helpxml. Falling back to --help.";
127+
ConstructCommandParam fallback_help_cmd_param{
128+
.bin_path = bin_path,
129+
.home = home,
130+
.args = {"--help"},
131+
.envs = envs,
132+
.working_dir = working_dir,
133+
.command_name = bin,
134+
};
135+
if (auto fallback_cmd = ConstructCommand(fallback_help_cmd_param);
136+
fallback_cmd.ok()) {
137+
stdout_str.clear();
138+
stderr_str.clear();
139+
RunWithManagedStdio(std::move(*fallback_cmd), nullptr, &stdout_str,
140+
&stderr_str);
141+
has_print = stdout_str.find("--print") != std::string::npos ||
142+
stderr_str.find("--print") != std::string::npos;
143+
}
144+
}
123145

124146
std::vector<std::string> args{"--wait_for_launcher",
125147
std::to_string(timeout.count())};

0 commit comments

Comments
 (0)