1
1
/*
2
- * Copyright (C) 2018 Canonical, Ltd.
2
+ * Copyright (C) 2018-2019 Canonical, Ltd.
3
3
*
4
4
* This program is free software; you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License as published by
@@ -25,22 +25,27 @@ namespace mpl = multipass::logging;
25
25
26
26
namespace
27
27
{
28
- void write_shutdown_message (mp::SSHSession& ssh_session, const std::chrono::minutes& time_left, const std::string& name)
28
+ void write_shutdown_message (mp::optional<mp::SSHSession>& ssh_session, const std::chrono::minutes& time_left,
29
+ const std::string& name)
29
30
{
30
- if (time_left > std::chrono::milliseconds::zero () )
31
+ if (ssh_session )
31
32
{
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));
35
- }
36
- else
37
- {
38
- ssh_session.exec (fmt::format (" wall The system is going down for poweroff now" ));
33
+ if (time_left > std::chrono::milliseconds::zero ())
34
+ {
35
+ ssh_session->exec (
36
+ fmt::format (" wall \" The system is going down for poweroff in {} minute{}, use 'multipass stop "
37
+ " --cancel {}' to cancel the shutdown.\" " ,
38
+ time_left.count (), time_left > std::chrono::minutes (1 ) ? " s" : " " , name));
39
+ }
40
+ else
41
+ {
42
+ ssh_session->exec (fmt::format (" wall The system is going down for poweroff now" ));
43
+ }
39
44
}
40
45
}
41
46
} // namespace
42
47
43
- mp::DelayedShutdownTimer::DelayedShutdownTimer (VirtualMachine* virtual_machine, SSHSession&& session)
48
+ mp::DelayedShutdownTimer::DelayedShutdownTimer (VirtualMachine* virtual_machine, mp::optional< SSHSession> && session)
44
49
: virtual_machine{virtual_machine}, ssh_session{std::move (session)}
45
50
{
46
51
}
@@ -49,8 +54,11 @@ mp::DelayedShutdownTimer::~DelayedShutdownTimer()
49
54
{
50
55
if (shutdown_timer.isActive ())
51
56
{
52
- // exit_code() is here to make sure the command finishes before continuing in the dtor
53
- ssh_session.exec (" wall The system shutdown has been cancelled" ).exit_code ();
57
+ if (ssh_session)
58
+ {
59
+ // exit_code() is here to make sure the command finishes before continuing in the dtor
60
+ ssh_session->exec (" wall The system shutdown has been cancelled" ).exit_code ();
61
+ }
54
62
mpl::log (mpl::Level::info, virtual_machine->vm_name , fmt::format (" Cancelling delayed shutdown" ));
55
63
virtual_machine->state = VirtualMachine::State::running;
56
64
}
0 commit comments