File: gcplogging_linux.go

package info (click to toggle)
docker.io 20.10.24%2Bdfsg1-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 60,824 kB
  • sloc: sh: 5,621; makefile: 593; ansic: 179; python: 162; asm: 7
file content (27 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package gcplogs // import "github.com/docker/docker/daemon/logger/gcplogs"

import (
	"os"

	"github.com/docker/docker/dockerversion"
	"github.com/docker/docker/pkg/homedir"
	"github.com/sirupsen/logrus"
)

// 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.
// 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).
// So we forcibly set HOME so as to avoid call to os/user/Current()
func ensureHomeIfIAmStatic() error {
	// Note: dockerversion.IAmStatic is only available for linux.
	// So we need to use them in this gcplogging_linux.go rather than in gcplogging.go
	if dockerversion.IAmStatic == "true" && os.Getenv("HOME") == "" {
		home := homedir.Get()
		logrus.Warnf("gcplogs requires HOME to be set for static daemon binary. Forcibly setting HOME to %s.", home)
		os.Setenv("HOME", home)
	}
	return nil
}