diff options
Diffstat (limited to 'bbot/machine.cxx')
-rw-r--r-- | bbot/machine.cxx | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/bbot/machine.cxx b/bbot/machine.cxx index 8cad3f9..460e802 100644 --- a/bbot/machine.cxx +++ b/bbot/machine.cxx @@ -104,15 +104,23 @@ namespace bbot uint16_t tftp_port); virtual bool - shutdown () override; + shutdown (size_t& seconds) override; virtual void forcedown () override; - private: + virtual void + suspend () override; + bool - wait (size_t seconds); + wait (size_t& seconds) override; + + using machine::wait; + virtual void + print_info (diag_record&) override; + + private: void monitor_command (const string&); @@ -123,6 +131,7 @@ namespace bbot string tap; // Tap network interface. uint16_t port; // TFTP port. + string vnc; // QEMU VNC TCP addr:port. path monitor; // QEMU monitor UNIX socket. process proc; }; @@ -140,6 +149,7 @@ namespace bbot br (br), tap (create_tap (br, port)), port (port), + vnc ("127.0.0.1:" + to_string (5900 + stoul (tc_num))), monitor ("/tmp/" + tc_name + "-monitor") { tracer trace ("kvm_machine"); @@ -185,7 +195,7 @@ namespace bbot // // VNC & monitor. // - "-vnc", "localhost:" + tc_num, // 5900 + tc_num + "-vnc", "127.0.0.1:" + tc_num, // 5900 + tc_num "-monitor", "unix:" + monitor.string () + ",server,nowait"); } @@ -208,30 +218,45 @@ namespace bbot // forcedown(). // bool kvm_machine:: - shutdown () + shutdown (size_t& seconds) { monitor_command ("system_powerdown"); - // Wait for up to 10 seconds for the machine to shutdown. + // Wait for up to the specified number if seconds for the machine to + // shutdown. // - return wait (10); + return wait (seconds); } void kvm_machine:: forcedown () { monitor_command ("system_reset"); - wait (size_t (~0)); // Wait indefinitely. + wait (); + } + + void kvm_machine:: + suspend () + { + monitor_command ("stop"); + } + + void kvm_machine:: + print_info (diag_record& dr) + { + dr << info << "qemu pid: " << proc.id () + << info << "qemu vnc: " << vnc + << info << "qemu monitor: unix:" << monitor; } bool kvm_machine:: - wait (size_t sec) + wait (size_t& sec) try { tracer trace ("kvm_machine::wait"); bool t; - for (size_t i (0); !(t = proc.try_wait ()) && i != sec; ++i) + for (; !(t = proc.try_wait ()) && sec != 0; --sec) sleep (1); if (t) |