Source file
src/os/executable_procfs.go
1
2
3
4
5
6
7 package os
8
9 import (
10 "errors"
11 "runtime"
12 )
13
14 func executable() (string, error) {
15 var procfn string
16 switch runtime.GOOS {
17 default:
18 return "", errors.New("Executable not implemented for " + runtime.GOOS)
19 case "linux", "android":
20 procfn = "/proc/self/exe"
21 case "netbsd":
22 procfn = "/proc/curproc/exe"
23 }
24 path, err := Readlink(procfn)
25
26
27
28 return stringsTrimSuffix(path, " (deleted)"), err
29 }
30
31
32 func stringsTrimSuffix(s, suffix string) string {
33 if len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix {
34 return s[:len(s)-len(suffix)]
35 }
36 return s
37 }
38
View as plain text