Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Fixes #1614 - Protect cleanup code of plugin unload #1615

Merged
merged 1 commit into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixes #1614 - Protect cleanup code of plugin unload
  • Loading branch information
rashmigottipati committed Apr 27, 2017
commit 9f64383d91d2d266372e7c71ae2b2ef9fa2a2812
2 changes: 1 addition & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func New(cfg *Config) *pluginControl {
}).Debug("metric catalog created")

// Plugin Manager
c.pluginManager = newPluginManager(OptSetPprof(cfg.Pprof))
c.pluginManager = newPluginManager(OptSetPprof(cfg.Pprof), OptSetTempDirPath(cfg.TempDirPath))
controlLogger.WithFields(log.Fields{
"_block": "new",
}).Debug("plugin manager created")
Expand Down
38 changes: 28 additions & 10 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ type pluginManager struct {
pluginConfig *pluginConfig
pluginTags map[string]map[string]string
pprof bool
tempDirPath string
}

func newPluginManager(opts ...pluginManagerOpt) *pluginManager {
Expand All @@ -260,6 +261,13 @@ func newPluginManager(opts ...pluginManagerOpt) *pluginManager {

type pluginManagerOpt func(*pluginManager)

// OptSetPprof sets the pprof flag on the plugin manager
func OptSetTempDirPath(path string) pluginManagerOpt {
return func(p *pluginManager) {
p.tempDirPath = path
}
}

// OptSetPprof sets the pprof flag on the plugin manager
func OptSetPprof(pprof bool) pluginManagerOpt {
return func(p *pluginManager) {
Expand Down Expand Up @@ -582,22 +590,32 @@ func (p *pluginManager) UnloadPlugin(pl core.Plugin) (*loadedPlugin, serror.Snap
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Debugf("Removing plugin")
if err := os.RemoveAll(filepath.Dir(plugin.Details.Path)); err != nil {
if strings.Contains(plugin.Details.Path, p.tempDirPath) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if err := os.RemoveAll(filepath.Dir(plugin.Details.Path)); err != nil {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Error(err)
se := serror.New(err)
se.SetFields(map[string]interface{}{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
})
return nil, se
}
} else {
pmLogger.WithFields(log.Fields{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
}).Error(err)
se := serror.New(err)
se.SetFields(map[string]interface{}{
"plugin-type": plugin.TypeName(),
"plugin-name": plugin.Name(),
"plugin-version": plugin.Version(),
"plugin-path": plugin.Details.Path,
})
return nil, se
}).Debug("Nothing to delete as temp path is empty")
}

p.loadedPlugins.remove(plugin.Key())

// Remove any metrics from the catalog if this was a collector
Expand Down