mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
b86e3bee5a
Fix #29344 If HOME is not set, the gcplogs logging driver will call os/user.Current() via oauth2/google. However, in static binary, os/user.Current() leads to segfault due to a glibc issue that won't be fixed in a short term. (golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341) So we forcibly set HOME so as to avoid call to os/user/Current(). Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
23 lines
628 B
Go
23 lines
628 B
Go
// +build linux
|
|
|
|
package homedir
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/docker/docker/pkg/idtools"
|
|
)
|
|
|
|
// GetStatic returns the home directory for the current user without calling
|
|
// os/user.Current(). This is useful for static-linked binary on glibc-based
|
|
// system, because a call to os/user.Current() in a static binary leads to
|
|
// segfault due to a glibc issue that won't be fixed in a short term.
|
|
// (#29344, golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341)
|
|
func GetStatic() (string, error) {
|
|
uid := os.Getuid()
|
|
usr, err := idtools.LookupUID(uid)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return usr.Home, nil
|
|
}
|