forked from nsf/gocode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_posix.go
47 lines (43 loc) · 831 Bytes
/
os_posix.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
package main
import (
"flag"
"os"
"path/filepath"
"exec"
)
func CreateSockFlag(name, desc string) *string {
return flag.String(name, "unix", desc)
}
func IsTerminationSignal(sig os.Signal) bool {
usig, ok := sig.(os.UnixSignal)
if !ok {
return false
}
if usig == os.SIGINT || usig == os.SIGTERM {
return true
}
return false
}
// Full path of the current executable
func GetExecutableFileName() string {
// try readlink first
path, err := os.Readlink("/proc/self/exe")
if err == nil {
return path
}
// use argv[0]
path = os.Args[0]
if !filepath.IsAbs(path) {
cwd, _ := os.Getwd()
path = filepath.Join(cwd, path)
}
if fileExists(path) {
return path
}
// Fallback : use "gocode" and assume we are in the PATH...
path, err = exec.LookPath("gocode")
if err == nil {
return path
}
return ""
}