iron_go icon indicating copy to clipboard operation
iron_go copied to clipboard

darwin: config throws `Error getting home directory: exec: "sh": executable file not found in $PATH`

Open polds opened this issue 10 years ago • 7 comments

I've been experiencing this now for several months and a co-worker of mine sat down and traced this error all the way back to this line:

https://github.com/iron-io/iron_go/blob/master/config/homedir.go#L57

When building on Darwin it throws the error:

Error getting home directory: exec: "sh": executable file not found in $PATH

I found that if we modified the line to use an absolute path to the sh executable it works like following:

cmd := exec.Command("/bin/sh", "-c", "eval echo ~$USER")

I realize that as that function is Unix specific /bin/sh is not likely going to be the same across all platforms as such I have not submitted a PR.

polds avatar Sep 01 '15 05:09 polds

Sorry, missed this one. Thanks for tracking that down. Going to try a few different things and will reference this issue when we find a solution.

rdallman avatar Sep 18 '15 21:09 rdallman

upstream code has changed to grep /etc/passwd - https://github.com/mitchellh/go-homedir/blob/master/homedir.go

I could try updating to that and seeing if it works if you are not currently working on this @rdallman .

nikhilm avatar Oct 29 '15 19:10 nikhilm

sure, worth syncing with upstream @nikhilm

rdallman avatar Oct 29 '15 21:10 rdallman

FWIW i can't reproduce this in OS X Yosemite, Go 1.5 because it can successfully find sh even without the /bin prefix. @polds What "Darwin" are you using exactly?

nikhilm avatar Oct 29 '15 22:10 nikhilm

homedir tries getent then falls back to the same shell approach. getent does not return a valid result on Mac (at least my mac), so it will lead to the same failure.

nikhilm avatar Oct 29 '15 22:10 nikhilm

@nikhilm I'm now on El Capitan Go 1.5.1, at time of reporting I was on Yosemite Go 1.4.

We ran into an instance where calling os.Clearenv() can once again get this problem to present itself.

polds avatar Oct 29 '15 22:10 polds

Thanks for the os.Clearenv() tip. I'll try with that.

nikhilm avatar Oct 29 '15 23:10 nikhilm