2018-02-05 16:05:59 -05:00
|
|
|
package gcplogs // import "github.com/docker/docker/daemon/logger/gcplogs"
|
2016-12-16 09:50:14 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/docker/docker/dockerversion"
|
|
|
|
"github.com/docker/docker/pkg/homedir"
|
2017-07-26 14:42:13 -07:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-12-16 09:50:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ensureHomeIfIAmStatic ensure $HOME to be set if dockerversion.IAmStatic is "true".
|
|
|
|
// See issue #29344: gcplogs segfaults (static binary)
|
|
|
|
// If HOME is not set, logging.NewClient() will call os/user.Current() via oauth2/google.
|
2019-09-23 22:16:38 +00:00
|
|
|
// If compiling statically, make sure osusergo build tag is also used to prevent a segfault
|
|
|
|
// due to a glibc issue that won't be fixed in a short term
|
|
|
|
// (see golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341).
|
2016-12-16 09:50:14 +00:00
|
|
|
// So we forcibly set HOME so as to avoid call to os/user/Current()
|
|
|
|
func ensureHomeIfIAmStatic() error {
|
2019-09-23 22:16:38 +00:00
|
|
|
// Note: dockerversion.IAmStatic is only available for linux.
|
2016-12-16 09:50:14 +00:00
|
|
|
// So we need to use them in this gcplogging_linux.go rather than in gcplogging.go
|
|
|
|
if dockerversion.IAmStatic == "true" && os.Getenv("HOME") == "" {
|
2019-09-23 22:16:38 +00:00
|
|
|
home := homedir.Get()
|
2016-12-16 09:50:14 +00:00
|
|
|
logrus.Warnf("gcplogs requires HOME to be set for static daemon binary. Forcibly setting HOME to %s.", home)
|
|
|
|
os.Setenv("HOME", home)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|