-
-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathexecutable_linux.go
More file actions
28 lines (25 loc) · 731 Bytes
/
executable_linux.go
File metadata and controls
28 lines (25 loc) · 731 Bytes
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
//go:build linux
package util
import (
"errors"
"os"
"path/filepath"
)
// Executable returns the path name for the executable that started the current process.
// On non-Linux systems, it behaves like os.Executable.
// On Linux, it returns the path to the executable as specified in the command line arguments.
func Executable() (string, error) {
executable := os.Args[0]
if len(executable) == 0 {
return "", errors.New("executable path is empty")
}
if executable[0] != '/' {
wd, err := os.Getwd()
if err != nil {
return "", err
}
// If the executable path is relative, prepend the current working directory to form an absolute path.
executable = filepath.Join(wd, executable)
}
return executable, nil
}