MCPcopy
hub / github.com/opencontainers/runc / orderNamespacePaths

Method orderNamespacePaths

libcontainer/container_linux.go:990–1019  ·  view source on GitHub ↗

orderNamespacePaths sorts namespace paths into a list of paths that we can setns in order.

(namespaces map[configs.NamespaceType]string)

Source from the content-addressed store, hash-verified

988// orderNamespacePaths sorts namespace paths into a list of paths that we
989// can setns in order.
990func (c *Container) orderNamespacePaths(namespaces map[configs.NamespaceType]string) ([]string, error) {
991 paths := []string{}
992 for _, ns := range configs.NamespaceTypes() {
993
994 // Remove namespaces that we don't need to join.
995 if !c.config.Namespaces.Contains(ns) {
996 continue
997 }
998
999 if p, ok := namespaces[ns]; ok && p != "" {
1000 // check if the requested namespace is supported
1001 if !configs.IsNamespaceSupported(ns) {
1002 return nil, fmt.Errorf("namespace %s is not supported", ns)
1003 }
1004 // only set to join this namespace if it exists
1005 if _, err := os.Lstat(p); err != nil {
1006 return nil, fmt.Errorf("namespace path: %w", err)
1007 }
1008 // do not allow namespace path with comma as we use it to separate
1009 // the namespace paths
1010 if strings.ContainsRune(p, ',') {
1011 return nil, fmt.Errorf("invalid namespace path %s", p)
1012 }
1013 paths = append(paths, fmt.Sprintf("%s:%s", configs.NsName(ns), p))
1014 }
1015
1016 }
1017
1018 return paths, nil
1019}
1020
1021func encodeIDMapping(idMap []configs.IDMap) ([]byte, error) {
1022 data := bytes.NewBuffer(nil)

Callers 1

bootstrapDataMethod · 0.95

Calls 4

NamespaceTypesFunction · 0.92
IsNamespaceSupportedFunction · 0.92
NsNameFunction · 0.92
ContainsMethod · 0.80

Tested by

no test coverage detected