If $HOME is not set, return homedir from /etc/passwd#11287
If $HOME is not set, return homedir from /etc/passwd#11287tiborvass merged 1 commit intomoby:masterfrom
Conversation
Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan)
|
Not sure if this is a valid concern, but what if someone is calling this method in order to determine if $HOME is set or not - I think this will return a false positive. And, is it ok that this pulls in libcontainer into the 'homedir' package? |
|
If you want to check if HOME is set you should call os.GetEnv(HOME). As far as the second question. I don't know. But if the goal of the homedir package is to get the homedir, I think my solution is more correct then what we currently have. |
|
Perhaps we need a GetEffectiveHome() type of func - then people can decide if they want the current HOME/USERPROFILE env var value or if they want to find the user's home dir (meaning do what Dan added if necessary). |
|
The |
|
I dunno, |
|
Ha, yes, @LK4D4 is correct. So, I thought there was a general rule that |
|
I was kind of shocked standard golang user does not support this on X86_64 machines. |
|
It does, but not when combined with static compilation.
|
|
Yeah, it calls glibc functions. |
|
LGTM |
|
We can revisit standaloneness in LGTM |
If $HOME is not set, return homedir from /etc/passwd
About github.com/opencontainers/runc/libcontainer/user: According to opencontainers/runc@195d8d5 this package has two functions: - Have a static implementation of user lookup, which is now supported in the os/user stdlib package with the osusergo build tag, but wasn't at the time. - Have extra functions that os/user doesn't have, but none of those are used in homedir. Since moby#11287, homedir depended directly on libcontainer's user package for CurrentUser(). This is being replaced with os/user.Current(), because all of our static binaries are compiled with the osusergo tag, and for dynamic libraries it is more correct to use libc's implementation than parsing /etc/passwd. About github.com/docker/docker/pkg/idtools: Only dependency was from GetStatic() which uses idtools.LookupUID(uid). The implementation of idtools.LookupUID just calls to github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks to exec-ing to getent (since moby#27599). This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out of supporting nss lookups in static binaries via exec-ing to getent for the homedir package. If homedir package users need to support nss lookups, they are advised to compile dynamically instead. Signed-off-by: Tibor Vass <tibor@docker.com>
About github.com/opencontainers/runc/libcontainer/user: According to opencontainers/runc@195d8d5 this package has two functions: - Have a static implementation of user lookup, which is now supported in the os/user stdlib package with the osusergo build tag, but wasn't at the time. - Have extra functions that os/user doesn't have, but none of those are used in homedir. Since moby/moby#11287, homedir depended directly on libcontainer's user package for CurrentUser(). This is being replaced with os/user.Current(), because all of our static binaries are compiled with the osusergo tag, and for dynamic libraries it is more correct to use libc's implementation than parsing /etc/passwd. About github.com/docker/docker/pkg/idtools: Only dependency was from GetStatic() which uses idtools.LookupUID(uid). The implementation of idtools.LookupUID just calls to github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks to exec-ing to getent (since moby/moby#27599). This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out of supporting nss lookups in static binaries via exec-ing to getent for the homedir package. If homedir package users need to support nss lookups, they are advised to compile dynamically instead. Signed-off-by: Tibor Vass <tibor@docker.com> Upstream-commit: a8608b5b67c77169276863cf31c6bc89a9ab3d8c Component: engine
About github.com/opencontainers/runc/libcontainer/user: According to opencontainers/runc@195d8d5 this package has two functions: - Have a static implementation of user lookup, which is now supported in the os/user stdlib package with the osusergo build tag, but wasn't at the time. - Have extra functions that os/user doesn't have, but none of those are used in homedir. Since moby#11287, homedir depended directly on libcontainer's user package for CurrentUser(). This is being replaced with os/user.Current(), because all of our static binaries are compiled with the osusergo tag, and for dynamic libraries it is more correct to use libc's implementation than parsing /etc/passwd. About github.com/docker/docker/pkg/idtools: Only dependency was from GetStatic() which uses idtools.LookupUID(uid). The implementation of idtools.LookupUID just calls to github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks to exec-ing to getent (since moby#27599). This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out of supporting nss lookups in static binaries via exec-ing to getent for the homedir package. If homedir package users need to support nss lookups, they are advised to compile dynamically instead. Signed-off-by: Tibor Vass <tibor@docker.com> Signed-off-by: zach <Zachary.Joyner@linux.com>
Running docker within a systemd unit file, the $HOME environment variable is not set. This causes docker to attempt to write the .docker directory to /. In a Atomic platform the / is immutable, so docker fails.
This patch will look up the users homedir if the $HOME environment variable is not set.
Docker-DCO-1.1-Signed-off-by: Dan Walsh dwalsh@redhat.com (github: rhatdan)