gcplogging_linux.go 1.1 KB

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