forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gcplogs: forcibly set HOME on static UNIX binary
Fix moby#29344 If HOME is not set, the gcplogs logging driver will call os/user.Current() via oauth2/google. However, in static binary, os/user.Current() leads to segfault due to a glibc issue that won't be fixed in a short term. (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(). Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
- Loading branch information
1 parent
a2b12b5
commit b86e3be
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// +build linux | ||
|
||
package gcplogs | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/docker/docker/dockerversion" | ||
"github.com/docker/docker/pkg/homedir" | ||
) | ||
|
||
// 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. | ||
// However, in static binary, os/user.Current() leads to segfault due to a glibc issue that won't be fixed | ||
// in a short term. (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 and homedir.GetStatic() 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, err := homedir.GetStatic() | ||
if err != nil { | ||
return err | ||
} | ||
logrus.Warnf("gcplogs requires HOME to be set for static daemon binary. Forcibly setting HOME to %s.", home) | ||
os.Setenv("HOME", home) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !linux | ||
|
||
package gcplogs | ||
|
||
func ensureHomeIfIAmStatic() error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// +build linux | ||
|
||
package homedir | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/docker/docker/pkg/idtools" | ||
) | ||
|
||
// GetStatic returns the home directory for the current user without calling | ||
// os/user.Current(). This is useful for static-linked binary on glibc-based | ||
// system, because a call to os/user.Current() in a static binary leads to | ||
// segfault due to a glibc issue that won't be fixed in a short term. | ||
// (#29344, golang/go#13470, https://sourceware.org/bugzilla/show_bug.cgi?id=19341) | ||
func GetStatic() (string, error) { | ||
uid := os.Getuid() | ||
usr, err := idtools.LookupUID(uid) | ||
if err != nil { | ||
return "", err | ||
} | ||
return usr.Home, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// +build !linux | ||
|
||
package homedir | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// GetStatic is not needed for non-linux systems. | ||
// (Precisely, it is needed only for glibc-based linux systems.) | ||
func GetStatic() (string, error) { | ||
return "", errors.New("homedir.GetStatic() is not supported on this system") | ||
} |