forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_linux.go
47 lines (39 loc) · 814 Bytes
/
plugin_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// +build linux
package core
import (
"os"
"path/filepath"
"plugin"
"strings"
"v2ray.com/core/app/log"
"v2ray.com/core/common/platform"
)
func loadPluginsInternal() error {
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()
log.Trace(newError("plugin (", metadata.Name, ") loaded."))
}
}
}
return nil
}