Skip to content

Commit

Permalink
Fixes intelsdi-x#1614 - Protect cleanup code of plugin unload
Browse files Browse the repository at this point in the history
  • Loading branch information
rashmigottipati committed Apr 26, 2017
1 parent 43a3504 commit 5f53a52
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,22 +582,36 @@ 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 GetDefaultConfig().TempDirPath != "" {
for _, e := range plugin.Details.Exec {
if strings.Contains(plugin.Details.Path, e) {
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
}).Info("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

0 comments on commit 5f53a52

Please sign in to comment.