Skip to content

Commit

Permalink
Extract func getAbs(), eval symlinks after, fix // bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry committed Sep 24, 2013
1 parent 22b2996 commit 10af4f5
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions osext_sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,35 @@ func executable() (string, error) {
break
}
}
var strpath string
if buf[0] != '/' {
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(string(buf)); err != nil {
if strpath, err := filepath.EvalSymlinks(strpath); err != nil {
return strpath, err
} else {
buf = []byte(strpath)
}
}
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
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
}

0 comments on commit 10af4f5

Please sign in to comment.