diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/go/pkg | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/go/pkg')
-rw-r--r-- | src/go/pkg/buildinfo/version.go | 6 | ||||
-rw-r--r-- | src/go/pkg/executable/executable.go | 43 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/go/pkg/buildinfo/version.go b/src/go/pkg/buildinfo/version.go new file mode 100644 index 000000000..55977a592 --- /dev/null +++ b/src/go/pkg/buildinfo/version.go @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package buildinfo + +// Version stores the agent's version number. It's set during the build process using build flags. +var Version = "v0.0.0" diff --git a/src/go/pkg/executable/executable.go b/src/go/pkg/executable/executable.go new file mode 100644 index 000000000..3f4e9e0de --- /dev/null +++ b/src/go/pkg/executable/executable.go @@ -0,0 +1,43 @@ +// 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 == "" { + return + } + + _, Name = filepath.Split(path) + Name = strings.TrimSuffix(Name, ".plugin") + + if strings.HasSuffix(Name, ".test") { + Name = "test" + } + + 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) + } +} |