Skip to content

Commit b1449fd

Browse files
committed
libct: use Namespaces.IsPrivate more
In these cases, this is exactly what we want to find out. Slightly improves performance and readability. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 1590491 commit b1449fd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libcontainer/configs/validate/rootless.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func rootlessEUIDMappings(config *configs.Config) error {
3434
return errors.New("rootless container requires user namespaces")
3535
}
3636
// We only require mappings if we are not joining another userns.
37-
if path := config.Namespaces.PathOf(configs.NEWUSER); path == "" {
37+
if config.Namespaces.IsPrivate(configs.NEWUSER) {
3838
if len(config.UIDMappings) == 0 {
3939
return errors.New("rootless containers requires at least one UID mapping")
4040
}

libcontainer/specconv/spec_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
415415
}
416416
config.Namespaces.Add(t, ns.Path)
417417
}
418-
if config.Namespaces.Contains(configs.NEWNET) && config.Namespaces.PathOf(configs.NEWNET) == "" {
418+
if config.Namespaces.IsPrivate(configs.NEWNET) {
419419
config.Networks = []*configs.Network{
420420
{
421421
Type: "loopback",
@@ -481,7 +481,7 @@ func CreateLibcontainerConfig(opts *CreateOpts) (*configs.Config, error) {
481481
// Only set it if the container will have its own cgroup
482482
// namespace and the cgroupfs will be mounted read/write.
483483
//
484-
hasCgroupNS := config.Namespaces.Contains(configs.NEWCGROUP) && config.Namespaces.PathOf(configs.NEWCGROUP) == ""
484+
hasCgroupNS := config.Namespaces.IsPrivate(configs.NEWCGROUP)
485485
hasRwCgroupfs := false
486486
if hasCgroupNS {
487487
for _, m := range config.Mounts {

0 commit comments

Comments
 (0)