syncthing/vendor/github.com/kardianos/osext/osext_procfs.go

37 lines
891 B
Go
Raw Normal View History

2014-05-02 08:05:48 +00:00
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2016-01-03 18:59:56 +00:00
// +build linux netbsd solaris dragonfly
2014-05-02 08:05:48 +00:00
package osext
import (
"errors"
2014-09-28 21:10:43 +00:00
"fmt"
2014-05-02 08:05:48 +00:00
"os"
"runtime"
2015-03-29 08:47:30 +00:00
"strings"
2014-05-02 08:05:48 +00:00
)
func executable() (string, error) {
switch runtime.GOOS {
case "linux":
2015-06-15 19:10:18 +00:00
const deletedTag = " (deleted)"
2015-03-29 08:47:30 +00:00
execpath, err := os.Readlink("/proc/self/exe")
if err != nil {
return execpath, err
}
2015-06-15 19:10:18 +00:00
execpath = strings.TrimSuffix(execpath, deletedTag)
execpath = strings.TrimPrefix(execpath, deletedTag)
return execpath, nil
2014-05-02 08:05:48 +00:00
case "netbsd":
return os.Readlink("/proc/curproc/exe")
2015-11-23 12:09:42 +00:00
case "dragonfly":
2014-05-02 08:05:48 +00:00
return os.Readlink("/proc/curproc/file")
2014-09-28 21:10:43 +00:00
case "solaris":
return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid()))
2014-05-02 08:05:48 +00:00
}
return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
}