diff options
Diffstat (limited to '')
-rw-r--r-- | src/go/collectors/go.d.plugin/agent/executable/executable.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/executable/executable.go b/src/go/collectors/go.d.plugin/agent/executable/executable.go new file mode 100644 index 000000000..cb09db1eb --- /dev/null +++ b/src/go/collectors/go.d.plugin/agent/executable/executable.go @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package executable + +import ( + "os" + "path/filepath" + "strings" +) + +var ( + Name string + Directory string +) + +func init() { + path, err := os.Executable() + if err != nil || path == "" { + Name = "go.d" + return + } + + _, Name = filepath.Split(path) + Name = strings.TrimSuffix(Name, ".plugin") + + if strings.HasSuffix(Name, ".test") { + Name = "test" + } + + // FIXME: can't use logger because of circular import + fi, err := os.Lstat(path) + if err != nil { + return + } + + if fi.Mode()&os.ModeSymlink != 0 { + realPath, err := filepath.EvalSymlinks(path) + if err != nil { + return + } + Directory = filepath.Dir(realPath) + } else { + Directory = filepath.Dir(path) + } +} |