Skip to content

Commit 4a03841

Browse files
authored
Merge pull request moby#5629 from jsternberg/rootless-config-once
buildkitd: remove sync.Once from isRootlessConfig
2 parents ca25771 + 866feca commit 4a03841

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

cmd/buildkitd/main.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"sort"
1414
"strconv"
1515
"strings"
16-
"sync"
1716

1817
"github.com/containerd/containerd/defaults"
1918
"github.com/containerd/containerd/remotes/docker"
@@ -544,26 +543,18 @@ func setDefaultConfig(cfg *config.Config) {
544543
}
545544
}
546545

547-
var (
548-
isRootlessConfigOnce sync.Once
549-
isRootlessConfigValue bool
550-
)
551-
552546
// isRootlessConfig is true if we should be using the rootless config
553547
// defaults instead of the normal defaults.
554548
func isRootlessConfig() bool {
555-
isRootlessConfigOnce.Do(func() {
556-
if !userns.RunningInUserNS() {
557-
// Default value is false so keep it that way.
558-
return
559-
}
560-
// if buildkitd is being executed as the mapped-root (not only EUID==0 but also $USER==root)
561-
// in a user namespace, we don't want to load the rootless changes in the
562-
// configuration.
563-
u := os.Getenv("USER")
564-
isRootlessConfigValue = u != "" && u != "root"
565-
})
566-
return isRootlessConfigValue
549+
if !userns.RunningInUserNS() {
550+
// Default value is false so keep it that way.
551+
return false
552+
}
553+
// if buildkitd is being executed as the mapped-root (not only EUID==0 but also $USER==root)
554+
// in a user namespace, we don't want to load the rootless changes in the
555+
// configuration.
556+
u := os.Getenv("USER")
557+
return u != "" && u != "root"
567558
}
568559

569560
func applyMainFlags(c *cli.Context, cfg *config.Config) error {

0 commit comments

Comments
 (0)