plugin_linux.go 814 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // +build linux
  2. package core
  3. import (
  4. "os"
  5. "path/filepath"
  6. "plugin"
  7. "strings"
  8. "v2ray.com/core/app/log"
  9. "v2ray.com/core/common/platform"
  10. )
  11. func loadPluginsInternal() error {
  12. pluginPath := platform.GetPluginDirectory()
  13. dir, err := os.Open(pluginPath)
  14. if err != nil {
  15. return err
  16. }
  17. defer dir.Close()
  18. files, err := dir.Readdir(-1)
  19. if err != nil {
  20. return err
  21. }
  22. for _, file := range files {
  23. if !file.IsDir() && strings.HasSuffix(file.Name(), ".so") {
  24. p, err := plugin.Open(filepath.Join(pluginPath, file.Name()))
  25. if err != nil {
  26. return err
  27. }
  28. f, err := p.Lookup(GetMetadataFuncName)
  29. if err != nil {
  30. return err
  31. }
  32. if gmf, ok := f.(GetMetadataFunc); ok {
  33. metadata := gmf()
  34. log.Trace(newError("plugin (", metadata.Name, ") loaded."))
  35. }
  36. }
  37. }
  38. return nil
  39. }