From 09bf3fb17fbad8db32e2b3e2bcca2af74c451733 Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Thu, 5 Jul 2018 14:58:38 +0200 Subject: [PATCH] overlord: add implicit slots to just snapd, if installed on startup Signed-off-by: Zygmunt Krynicki --- overlord/ifacestate/helpers.go | 9 +++++++++ overlord/ifacestate/implicit.go | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/overlord/ifacestate/helpers.go b/overlord/ifacestate/helpers.go index e8b502dafbb..a72fa40966c 100644 --- a/overlord/ifacestate/helpers.go +++ b/overlord/ifacestate/helpers.go @@ -104,6 +104,15 @@ func (m *InterfaceManager) addSnaps() error { if err != nil { return err } + // Before adding any snap scan the set of snaps we know about. If any of + // those is snapd then for the duration of this process always add + // implicit slots to snapd and not to any other type: os snap. + for _, snapInfo := range snaps { + if snapInfo.SnapName() == "snapd" { + implicitSlotsOnSnapd = true + break + } + } for _, snapInfo := range snaps { addImplicitSlots(snapInfo) if err := m.repo.AddSnap(snapInfo); err != nil { diff --git a/overlord/ifacestate/implicit.go b/overlord/ifacestate/implicit.go index 4249b5e8817..25596feef25 100644 --- a/overlord/ifacestate/implicit.go +++ b/overlord/ifacestate/implicit.go @@ -26,6 +26,17 @@ import ( "github.com/snapcore/snapd/snap" ) +// Flag indicating if implicit slots should be added to "snapd" snap. This +// is here because the interface manager is the only entity adding such +// slots and must ensure that: ubuntu-core -> core transition can run as +// before (both snaps have the implicit slots but that case is handled +// directly) and so that once "snapd" snap is installed only one snap in +// the system will hold implicit interfaces. +// +// This is set on startup of the interface manager, based on the presence +// of "snapd" snap in the state. +var implicitSlotsOnSnapd bool + // addImplicitSlots adds implicitly defined slots to a given snap. // // Only the OS snap has implicit slots. @@ -33,10 +44,20 @@ import ( // It is assumed that slots have names matching the interface name. Existing // slots are not changed, only missing slots are added. func addImplicitSlots(snapInfo *snap.Info) { - if snapInfo.Type != snap.TypeOS { + // Implicit slots can be added to the special "snapd" snap or to snaps with + // type "os". Currently there are no other snaps that gain implicit + // interfaces. + if snapInfo.Type != snap.TypeOS && snapInfo.InstanceName() != "snapd" { + return + } + + // If the manager has chosen to put implicit slots on the "snapd" snap + // then stop adding them to any other core snaps. + if implicitSlotsOnSnapd && snapInfo.InstanceName() != "snapd" { return } - // Ask each interface if it wants to be implcitly added. + + // Ask each interface if it wants to be implicitly added. for _, iface := range builtin.Interfaces() { si := interfaces.StaticInfoOf(iface) if (release.OnClassic && si.ImplicitOnClassic) || (!release.OnClassic && si.ImplicitOnCore) {