github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/daemon/logger/gcplogs/gcplogging_linux.go (about) 1 package gcplogs // import "github.com/docker/docker/daemon/logger/gcplogs" 2 3 import ( 4 "os" 5 6 "github.com/docker/docker/dockerversion" 7 "github.com/docker/docker/pkg/homedir" 8 "github.com/sirupsen/logrus" 9 ) 10 11 // ensureHomeIfIAmStatic ensure $HOME to be set if dockerversion.IAmStatic is "true". 12 // See issue #29344: gcplogs segfaults (static binary) 13 // If HOME is not set, logging.NewClient() will call os/user.Current() via oauth2/google. 14 // If compiling statically, make sure osusergo build tag is also used to prevent a segfault 15 // due to a glibc issue that won't be fixed in a short term 16 // (see golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341). 17 // So we forcibly set HOME so as to avoid call to os/user/Current() 18 func ensureHomeIfIAmStatic() error { 19 // Note: dockerversion.IAmStatic is only available for linux. 20 // So we need to use them in this gcplogging_linux.go rather than in gcplogging.go 21 if dockerversion.IAmStatic == "true" && os.Getenv("HOME") == "" { 22 home := homedir.Get() 23 logrus.Warnf("gcplogs requires HOME to be set for static daemon binary. Forcibly setting HOME to %s.", home) 24 os.Setenv("HOME", home) 25 } 26 return nil 27 }