Skip to content

Commit 591bae2

Browse files
Validation check for main instance during restart
1 parent 89bfd8f commit 591bae2

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • base/cvd/cuttlefish/host/commands/cvd/cli/commands

base/cvd/cuttlefish/host/commands/cvd/cli/commands/restart.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,26 @@ Result<void> CvdDeviceRestartCommandHandler::Handle(
7272
std::vector<std::string> subcmd_args = request.SubcommandArguments();
7373
CF_EXPECT(ConsumeFlags(options.Flags(), subcmd_args));
7474

75-
auto [instance, unused] =
75+
auto [instance, group] =
7676
CF_EXPECT(selector::SelectInstance(instance_manager_, request),
7777
"Unable to select an instance");
7878

79+
const auto& instances = group.Instances();
80+
if (!instances.empty() && instance.Id() == instances[0].Id()) {
81+
bool other_active = false;
82+
for (const auto& inst : instances) {
83+
if (inst.Id() != instance.Id() && inst.IsActive()) {
84+
other_active = true;
85+
break;
86+
}
87+
}
88+
CF_EXPECTF(
89+
!other_active,
90+
"Restarting the first instance (ID: {}) is not allowed "
91+
"while other instances are running. Restart the entire group instead.",
92+
instance.Id());
93+
}
94+
7995
CF_EXPECT(
8096
instance.Restart(std::chrono::seconds(options.wait_for_launcher_seconds),
8197
std::chrono::seconds(options.boot_timeout_seconds)));

0 commit comments

Comments
 (0)