| 585 | } |
| 586 | |
| 587 | void RuntimeControlService::HandleMessage(const ipc::Message& message) { |
| 588 | if (message.channel == ipc::Channel::kControl && |
| 589 | message.kind == ipc::Kind::kRequest && |
| 590 | message.type == "runtime.command") { |
| 591 | ipc::Message resp; |
| 592 | resp.kind = ipc::Kind::kResponse; |
| 593 | resp.channel = ipc::Channel::kControl; |
| 594 | resp.type = "runtime.command.result"; |
| 595 | resp.vm_id = vm_id_; |
| 596 | resp.request_id = message.request_id; |
| 597 | resp.fields["ok"] = "true"; |
| 598 | |
| 599 | auto it = message.fields.find("command"); |
| 600 | if (it == message.fields.end()) { |
| 601 | resp.fields["ok"] = "false"; |
| 602 | resp.fields["error"] = "missing command"; |
| 603 | Send(resp); |
| 604 | return; |
| 605 | } |
| 606 | const std::string& cmd = it->second; |
| 607 | if (cmd == "stop") { |
| 608 | if (vm_) vm_->RequestStop(); |
| 609 | } else if (cmd == "shutdown") { |
| 610 | if (vm_ && vm_->IsGuestAgentConnected()) { |
| 611 | vm_->GuestAgentShutdown("powerdown"); |
| 612 | } else if (vm_) { |
| 613 | vm_->TriggerPowerButton(); |
| 614 | static const char kPoweroff[] = "\npoweroff\n"; |
| 615 | vm_->InjectConsoleBytes( |
| 616 | reinterpret_cast<const uint8_t*>(kPoweroff), |
| 617 | sizeof(kPoweroff) - 1); |
| 618 | } |
| 619 | } else if (cmd == "reboot") { |
| 620 | if (vm_ && vm_->IsGuestAgentConnected()) { |
| 621 | vm_->GuestAgentShutdown("reboot"); |
| 622 | } else if (vm_) { |
| 623 | vm_->RequestStop(); |
| 624 | resp.fields["note"] = "guest agent unavailable, performed stop"; |
| 625 | } |
| 626 | } else if (cmd == "start") { |
| 627 | resp.fields["note"] = "runtime already started by process launch"; |
| 628 | } else if (cmd == "sync-time") { |
| 629 | if (vm_ && vm_->IsGuestAgentConnected()) { |
| 630 | vm_->GuestAgentSyncTime(); |
| 631 | } else if (vm_) { |
| 632 | resp.fields["note"] = "guest agent not connected"; |
| 633 | } |
| 634 | } else { |
| 635 | resp.fields["ok"] = "false"; |
| 636 | resp.fields["error"] = "unknown command"; |
| 637 | } |
| 638 | Send(resp); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | if (message.channel == ipc::Channel::kControl && |
| 643 | message.kind == ipc::Kind::kRequest && |
| 644 | message.type == "runtime.update_network") { |
no test coverage detected