-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
os/user: implement basic cgo-free Current user function #14626
Labels
Comments
SGTM.
|
CL https://golang.org/cl/20192 mentions this issue. |
Arista-Jenkins
pushed a commit
to aristanetworks/glog
that referenced
this issue
Feb 2, 2017
It's not necessary, and pretty much nothing else in our code base depends on it. Also it doesn't really work when cross-compiling. In fact it was "fixed" in Go 1.7 [golang/go#14626] to return the value of $USER, which is what this commit basically does. Change-Id: I35fd95c6913a9d11112a0b1fd061b73549fd91c0
gopherbot
pushed a commit
that referenced
this issue
Sep 9, 2018
Per #27524 there are situations where the username for the uid does not match the value in the $USER environment variable and it seems sensible to choose the value in /etc/passwd when they disagree. This may make the Current() call slightly more expensive, since we read /etc/passwd with cgo disabled instead of just checking the environment. However, we cache the result of Current() calls, so we only invoke this cost once in the lifetime of the process. Fixes #14626. Fixes #27524. Updates #24884. Change-Id: I0dcd224cf7f61dd5292f3fcc363aa2e9656a2cb1 Reviewed-on: https://go-review.googlesource.com/134218 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
os/user.Current
returns a (*User, error). User is:When the binary is built without cgo,
os/user.Current
returns an error.This bites people often (most recently: #14625) and is confusing. I propose that in cgo-free builds, we make Current work using:
and only if either Username or HomeDir are empty do we return an error.
I think we can ignore the User.Name field.
The text was updated successfully, but these errors were encountered: