From b1eb6711b76a3ef559b917cf68caa84a1088d44b Mon Sep 17 00:00:00 2001 From: James Shubin Date: Sun, 16 Dec 2018 16:07:42 -0500 Subject: [PATCH] engine: resources: Work around a subtle embedded res bug This is a subtle issue that was found that caused a panic. This should solve things for now, but it would be wise to build embedded or composite resources sparingly until we we're certain this would work the way we wanted for all scenarios. --- engine/resources/cron.go | 1 + engine/resources/nspawn.go | 1 + engine/resources/svc.go | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/resources/cron.go b/engine/resources/cron.go index f1b37746..f38ecd2b 100644 --- a/engine/resources/cron.go +++ b/engine/resources/cron.go @@ -79,6 +79,7 @@ type CronRes struct { traits.Base traits.Edgeable traits.Recvable + traits.Refreshable // needed because we embed a svc res init *engine.Init diff --git a/engine/resources/nspawn.go b/engine/resources/nspawn.go index 3171c9f6..cbd473ad 100644 --- a/engine/resources/nspawn.go +++ b/engine/resources/nspawn.go @@ -52,6 +52,7 @@ func init() { type NspawnRes struct { traits.Base // add the base methods without re-implementation //traits.Groupable // TODO: this would be quite useful for this resource + traits.Refreshable // needed because we embed a svc res init *engine.Init diff --git a/engine/resources/svc.go b/engine/resources/svc.go index 5c0d888b..8719eb73 100644 --- a/engine/resources/svc.go +++ b/engine/resources/svc.go @@ -280,7 +280,17 @@ func (obj *SvcRes) CheckApply(apply bool) (checkOK bool, err error) { var running = (activestate.Value == dbus.MakeVariant("active")) var stateOK = ((obj.State == "") || (obj.State == "running" && running) || (obj.State == "stopped" && !running)) - var startupOK = true // XXX: DETECT AND SET + var startupOK = true // XXX: DETECT AND SET + + // NOTE: if this svc resource is embedded as a composite resource inside + // of another resource using a technique such as `makeComposite()`, then + // the Init of the embedded resource is traditionally passed through and + // identical to the parent's Init. As a result, the data matches what is + // expected from the parent. (So this luckily turns out to be actually a + // thing that does help, although it is important to add the Refreshable + // trait to the parent resource, or we'll panic when we call this line.) + // It might not be recommended to use the Watch method without a thought + // to what actually happens when we would run Send(), and other methods. var refresh = obj.init.Refresh() // do we have a pending reload to apply? if stateOK && startupOK && !refresh {