Skip to content

Commit 4bc5889

Browse files
committed
daemon, o/i/apparmorprompting: simplify ShutDown
1 parent c6ba72b commit 4bc5889

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

daemon/api_prompting_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ type fakeInterfacesRequestsManager struct {
5858
iface string
5959
pid int32
6060
cgroup string
61-
snapdShuttingDown <-chan struct{}
6261
id prompting.IDType // used for prompt ID or rule ID
6362
ruleConstraintsJSON prompting.ConstraintsJSON
6463
constraintsPatchJSON prompting.ConstraintsJSON
@@ -732,7 +731,6 @@ func (s *promptingSuite) TestPostInterfacesRequestsHappy(c *C) {
732731
c.Check(s.manager.snap, Equals, expectedSnap)
733732
c.Check(s.manager.pid, Equals, fakePID)
734733
c.Check(s.manager.cgroup, Equals, fakeCgroup)
735-
c.Check(s.manager.snapdShuttingDown, NotNil)
736734

737735
// Check return value
738736
responseBody, ok := rsp.Result.(daemon.PostInterfacesRequestsResponse)

overlord/ifacestate/apparmorprompting/prompting.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ type InterfacesRequestsManager struct {
8585
// listener readiness.
8686
listenerAlreadySignalled chan struct{}
8787

88+
// snapdShuttingDown is closed when overlord.ShutDown is called to
89+
// signal that the daemon is going to be stopped and the
90+
// InterfacesRequestsManager needs to stop receiving requests and
91+
// finish handling existing requests.
8892
snapdShuttingDown chan struct{}
89-
shuttingDownOnce sync.Once
93+
shutdown bool
9094

9195
askRequests chan *prompting.Request
9296
}
@@ -390,9 +394,11 @@ func (m *InterfacesRequestsManager) Ask(uid uint32, iface, snap string, pid int3
390394
// ShutDown stops the listener, prompt DB, and rule DB from receiving new
391395
// requests.
392396
func (m *InterfacesRequestsManager) ShutDown() {
393-
m.shuttingDownOnce.Do(func() {
394-
close(m.snapdShuttingDown)
395-
})
397+
if m.shutdown {
398+
return
399+
}
400+
close(m.snapdShuttingDown)
401+
m.shutdown = true
396402
}
397403

398404
// Stop closes the listener, prompt DB, and rule DB. Stop is idempotent, and

0 commit comments

Comments
 (0)