plugin_linux.go 790 B

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