From 203405b4b267874ec949bb079277230b402206ae Mon Sep 17 00:00:00 2001 From: Jeff Lindsay Date: Fri, 8 May 2015 14:57:05 -0700 Subject: [PATCH] Adding mutex to extpointHandlers Handlers may be registered during daemon start, not just package init, so we have to protect the map with a mutex as well. Signed-off-by: Jeff Lindsay --- plugins/plugins.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/plugins.go b/plugins/plugins.go index 90ffa445d459a..ec7b67523073d 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -9,7 +9,7 @@ import ( var ( activePlugins = &plugins{plugins: make(map[string]*Plugin)} - extpointHandlers = make(map[string]func(string, *Client)) + extpointHandlers = &handlers{handlers: make(map[string]func(string, *Client))} ) type plugins struct { @@ -17,6 +17,11 @@ type plugins struct { plugins map[string]*Plugin } +type handlers struct { + sync.Mutex + handlers map[string]func(string, *Client) +} + type Manifest struct { Implements []string } @@ -44,8 +49,11 @@ func (p *Plugin) Activate() error { } p.Manifest = m + extpointHandlers.Lock() + defer extpointHandlers.Unlock() + for _, iface := range m.Implements { - handler, handled := extpointHandlers[iface] + handler, handled := extpointHandlers.handlers[iface] if !handled { continue } @@ -103,5 +111,7 @@ func Active() []*Plugin { } func Handle(iface string, fn func(string, *Client)) { - extpointHandlers[iface] = fn + extpointHandlers.Lock() + defer extpointHandlers.Unlock() + extpointHandlers.handlers[iface] = fn }