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

37 lines
891 B
Go
Raw Normal View History

2014-05-02 10:05:48 +02: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 19:59:56 +01:00
// +build linux netbsd solaris dragonfly
2014-05-02 10:05:48 +02:00
package osext
import (
"errors"
2014-09-28 23:10:43 +02:00
"fmt"
2014-05-02 10:05:48 +02:00
"os"
"runtime"
2015-03-29 10:47:30 +02:00
"strings"
2014-05-02 10:05:48 +02:00
)
func executable() (string, error) {
switch runtime.GOOS {
case "linux":
2015-06-15 21:10:18 +02:00
const deletedTag = " (deleted)"
2015-03-29 10:47:30 +02:00
execpath, err := os.Readlink("/proc/self/exe")
if err != nil {
return execpath, err
}
2015-06-15 21:10:18 +02:00
execpath = strings.TrimSuffix(execpath, deletedTag)
execpath = strings.TrimPrefix(execpath, deletedTag)
return execpath, nil
2014-05-02 10:05:48 +02:00
case "netbsd":
return os.Readlink("/proc/curproc/exe")
2015-11-23 13:09:42 +01:00
case "dragonfly":
2014-05-02 10:05:48 +02:00
return os.Readlink("/proc/curproc/file")
2014-09-28 23:10:43 +02:00
case "solaris":
return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid()))
2014-05-02 10:05:48 +02:00
}
return "", errors.New("ExecPath not implemented for " + runtime.GOOS)
}