Add Self func to reexec pkg to return the current binary path

Signed-off-by: Michael Crosby <michael@docker.com>
Upstream-commit: 283ee108862da1db55a7cf944f20a245c096c388
Component: engine
This commit is contained in:
Michael Crosby
2014-08-13 11:14:33 -07:00
parent 09e4804b95
commit 1f8b0d9982
+15
View File
@@ -3,6 +3,8 @@ package reexec
import (
"fmt"
"os"
"os/exec"
"path/filepath"
)
var registeredInitializers = make(map[string]func())
@@ -28,3 +30,16 @@ func Init() bool {
return false
}
// Self returns the path to the current processes binary
func Self() string {
name := os.Args[0]
if filepath.Base(name) == name {
if lp, err := exec.LookPath(name); err == nil {
name = lp
}
}
return name
}