1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-05 09:47:56 -05:00
v2fly/plugin_linux.go

47 lines
790 B
Go
Raw Normal View History

2017-11-22 17:11:32 -05:00
// +build linux
package core
import (
"os"
"path/filepath"
"plugin"
"strings"
"v2ray.com/core/common/platform"
)
2017-11-22 17:15:14 -05:00
func loadPluginsInternal() error {
2017-11-22 17:11:32 -05:00
pluginPath := platform.GetPluginDirectory()
dir, err := os.Open(pluginPath)
if err != nil {
return err
}
defer dir.Close()
files, err := dir.Readdir(-1)
if err != nil {
return err
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".so") {
p, err := plugin.Open(filepath.Join(pluginPath, file.Name()))
if err != nil {
return err
}
f, err := p.Lookup(GetMetadataFuncName)
if err != nil {
return err
}
if gmf, ok := f.(GetMetadataFunc); ok {
metadata := gmf()
2017-12-19 15:28:12 -05:00
newError("plugin (", metadata.Name, ") loaded.").WriteToLog()
2017-11-22 17:11:32 -05:00
}
}
}
return nil
}