summaryrefslogtreecommitdiff
diff options
authorOliver Calder <oliver.calder@canonical.com>2023-09-19 14:39:19 -0500
committerMichael Vogt <michael.vogt@gmail.com>2023-09-21 08:50:50 +0200
commit2d35a87cb3c523cb69904fd203961932c32b0eff (patch)
treef115ff0ad9ddddba93c401ae93e96b236c0ff462
parentd0cfb81163b1d5600b629fb3fd7d3baff75d7039 (diff)
usersession/agent: only close session bus if non-nil
On Ubuntu 16.04, ssh sessions may not have a D-Bus session bus, resulting in the `bus` field of the session agent being nil. If this is the case, calling `s.bus.Close()` results in a nil pointer exception. This commit adds a check of `s.bus` (like those found elsewhere in session_agent.go) before calling `s.bus.Close()` during a session shutdown. Discovered-by: Andrew Phelps <andrew.phelps@canonical.com> Signed-off-by: Oliver Calder <oliver.calder@canonical.com>
-rw-r--r--usersession/agent/session_agent.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/usersession/agent/session_agent.go b/usersession/agent/session_agent.go
index 34ad645ac0..b3d064cd1e 100644
--- a/usersession/agent/session_agent.go
+++ b/usersession/agent/session_agent.go
@@ -276,7 +276,10 @@ func (s *SessionAgent) shutdownServerOnKill() error {
// Historically We do something similar in the main daemon
// logic as well.
s.listener.Close()
- s.bus.Close()
+ // Note that session bus may be nil, see the comment in tryConnectSessionBus.
+ if s.bus != nil {
+ s.bus.Close()
+ }
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
defer cancel()
return s.serve.Shutdown(ctx)