Browse Source

bump(bitbucket.org/kardianos/osext): 364fb577de68

Ben Johnson 12 years ago
parent
commit
e1003a8623
1 changed files with 29 additions and 11 deletions
  1. 29 11
      third_party/bitbucket.org/kardianos/osext/osext_sysctl.go

+ 29 - 11
third_party/bitbucket.org/kardianos/osext/osext_sysctl.go

@@ -8,6 +8,7 @@ package osext
 
 
 import (
 import (
 	"os"
 	"os"
+	"path/filepath"
 	"runtime"
 	"runtime"
 	"syscall"
 	"syscall"
 	"unsafe"
 	"unsafe"
@@ -47,18 +48,35 @@ func executable() (string, error) {
 			break
 			break
 		}
 		}
 	}
 	}
+	var strpath string
 	if buf[0] != '/' {
 	if buf[0] != '/' {
-		if getwdError != nil {
-			return string(buf), getwdError
-		} else {
-			if buf[0] == '.' {
-				buf = buf[1:]
-			}
-			if startUpcwd[len(startUpcwd)-1] != '/' {
-				return startUpcwd + "/" + string(buf), nil
-			}
-			return startUpcwd + string(buf), nil
+		var e error
+		if strpath, e = getAbs(buf); e != nil {
+			return strpath, e
 		}
 		}
+	} else {
+		strpath = string(buf)
+	}
+	// darwin KERN_PROCARGS may return the path to a symlink rather than the
+	// actual executable
+	if runtime.GOOS == "darwin" {
+		if strpath, err := filepath.EvalSymlinks(strpath); err != nil {
+			return strpath, err
+		}
+	}
+	return strpath, nil
+}
+
+func getAbs(buf []byte) (string, error) {
+	if getwdError != nil {
+		return string(buf), getwdError
+	} else {
+		if buf[0] == '.' {
+			buf = buf[1:]
+		}
+		if startUpcwd[len(startUpcwd)-1] != '/' && buf[0] != '/' {
+			return startUpcwd + "/" + string(buf), nil
+		}
+		return startUpcwd + string(buf), nil
 	}
 	}
-	return string(buf), nil
 }
 }