@@ -25,16 +25,17 @@ namespace mpl = multipass::logging;
25
25
26
26
namespace
27
27
{
28
- std::string shutdown_message ( const std::chrono::minutes& time_left)
28
+ void write_shutdown_message (mp::SSHSession& ssh_session, const std::chrono::minutes& time_left, const std::string& name )
29
29
{
30
30
if (time_left > std::chrono::milliseconds::zero ())
31
31
{
32
- return fmt::format (" wall The system is going down for poweroff in {} minute{}" , time_left.count (),
33
- time_left > std::chrono::minutes (1 ) ? " s" : " " );
32
+ ssh_session.exec (fmt::format (" wall \" The system is going down for poweroff in {} minute{}, use 'multipass stop "
33
+ " --cancel {}' to cancel the shutdown.\" " ,
34
+ time_left.count (), time_left > std::chrono::minutes (1 ) ? " s" : " " , name));
34
35
}
35
36
else
36
37
{
37
- return fmt::format (" wall The system is going down for poweroff now" );
38
+ ssh_session. exec ( fmt::format (" wall The system is going down for poweroff now" ) );
38
39
}
39
40
}
40
41
} // namespace
@@ -48,6 +49,7 @@ mp::DelayedShutdownTimer::~DelayedShutdownTimer()
48
49
{
49
50
if (shutdown_timer.isActive ())
50
51
{
52
+ // exit_code() is here to make sure the command finishes before continuing in the dtor
51
53
ssh_session.exec (" wall The system shutdown has been cancelled" ).exit_code ();
52
54
mpl::log (mpl::Level::info, virtual_machine->vm_name , fmt::format (" Cancelling delayed shutdown" ));
53
55
virtual_machine->state = VirtualMachine::State::running;
@@ -66,13 +68,21 @@ void mp::DelayedShutdownTimer::start(const std::chrono::milliseconds delay)
66
68
fmt::format (" Shutdown request delayed for {} minute{}" ,
67
69
std::chrono::duration_cast<std::chrono::minutes>(delay).count (),
68
70
delay > std::chrono::minutes (1 ) ? " s" : " " ));
69
- ssh_session.exec (shutdown_message (std::chrono::duration_cast<std::chrono::minutes>(delay)));
71
+ write_shutdown_message (ssh_session, std::chrono::duration_cast<std::chrono::minutes>(delay),
72
+ virtual_machine->vm_name );
70
73
71
74
time_remaining = delay;
72
75
std::chrono::minutes time_elapsed{1 };
73
76
QObject::connect (&shutdown_timer, &QTimer::timeout, [this , delay, time_elapsed]() mutable {
74
77
time_remaining = delay - time_elapsed;
75
- ssh_session.exec (shutdown_message (std::chrono::duration_cast<std::chrono::minutes>(time_remaining)));
78
+
79
+ if (time_remaining <= std::chrono::minutes (5 ) ||
80
+ time_remaining % std::chrono::minutes (5 ) == std::chrono::minutes::zero ())
81
+ {
82
+ write_shutdown_message (ssh_session, std::chrono::duration_cast<std::chrono::minutes>(time_remaining),
83
+ virtual_machine->vm_name );
84
+ }
85
+
76
86
if (time_elapsed >= delay)
77
87
{
78
88
shutdown_timer.stop ();
@@ -90,7 +100,7 @@ void mp::DelayedShutdownTimer::start(const std::chrono::milliseconds delay)
90
100
}
91
101
else
92
102
{
93
- ssh_session. exec ( shutdown_message ( std::chrono::minutes::zero ()) );
103
+ write_shutdown_message (ssh_session, std::chrono::minutes::zero (), virtual_machine-> vm_name );
94
104
shutdown_instance ();
95
105
}
96
106
}
0 commit comments