gcplogging_linux.go 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. // +build linux
  2. package gcplogs
  3. import (
  4. "os"
  5. "github.com/Sirupsen/logrus"
  6. "github.com/docker/docker/dockerversion"
  7. "github.com/docker/docker/pkg/homedir"
  8. )
  9. // ensureHomeIfIAmStatic ensure $HOME to be set if dockerversion.IAmStatic is "true".
  10. // See issue #29344: gcplogs segfaults (static binary)
  11. // If HOME is not set, logging.NewClient() will call os/user.Current() via oauth2/google.
  12. // However, in static binary, os/user.Current() leads to segfault due to a glibc issue that won't be fixed
  13. // in a short term. (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 and homedir.GetStatic() 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, err := homedir.GetStatic()
  20. if err != nil {
  21. return err
  22. }
  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. }