Browse Source

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

Signed-off-by: Michael Crosby <michael@docker.com>
Michael Crosby 11 years ago
parent
commit
283ee10886
1 changed files with 15 additions and 0 deletions
  1. 15 0
      reexec/reexec.go

+ 15 - 0
reexec/reexec.go

@@ -3,6 +3,8 @@ package reexec
 import (
 import (
 	"fmt"
 	"fmt"
 	"os"
 	"os"
+	"os/exec"
+	"path/filepath"
 )
 )
 
 
 var registeredInitializers = make(map[string]func())
 var registeredInitializers = make(map[string]func())
@@ -28,3 +30,16 @@ func Init() bool {
 
 
 	return false
 	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
+}