github.com/rita33cool1/iot-system-gateway@v0.0.0-20200911033302-e65bde238cc5/docker-engine/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  // However, in static binary, os/user.Current() leads to segfault due to a glibc issue that won't be fixed
    15  // in a short term. (golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341)
    16  // So we forcibly set HOME so as to avoid call to os/user/Current()
    17  func ensureHomeIfIAmStatic() error {
    18  	// Note: dockerversion.IAmStatic and homedir.GetStatic() is only available for linux.
    19  	// So we need to use them in this gcplogging_linux.go rather than in gcplogging.go
    20  	if dockerversion.IAmStatic == "true" && os.Getenv("HOME") == "" {
    21  		home, err := homedir.GetStatic()
    22  		if err != nil {
    23  			return err
    24  		}
    25  		logrus.Warnf("gcplogs requires HOME to be set for static daemon binary. Forcibly setting HOME to %s.", home)
    26  		os.Setenv("HOME", home)
    27  	}
    28  	return nil
    29  }