github.com/kim0/docker@v0.6.2-0.20161130212042-4addda3f07e7/libcontainerd/utils_linux.go (about)

     1  package libcontainerd
     2  
     3  import (
     4  	containerd "github.com/docker/containerd/api/grpc/types"
     5  	"github.com/opencontainers/runtime-spec/specs-go"
     6  )
     7  
     8  func getRootIDs(s specs.Spec) (int, int, error) {
     9  	var hasUserns bool
    10  	for _, ns := range s.Linux.Namespaces {
    11  		if ns.Type == specs.UserNamespace {
    12  			hasUserns = true
    13  			break
    14  		}
    15  	}
    16  	if !hasUserns {
    17  		return 0, 0, nil
    18  	}
    19  	uid := hostIDFromMap(0, s.Linux.UIDMappings)
    20  	gid := hostIDFromMap(0, s.Linux.GIDMappings)
    21  	return uid, gid, nil
    22  }
    23  
    24  func hostIDFromMap(id uint32, mp []specs.IDMapping) int {
    25  	for _, m := range mp {
    26  		if id >= m.ContainerID && id <= m.ContainerID+m.Size-1 {
    27  			return int(m.HostID + id - m.ContainerID)
    28  		}
    29  	}
    30  	return 0
    31  }
    32  
    33  func systemPid(ctr *containerd.Container) uint32 {
    34  	var pid uint32
    35  	for _, p := range ctr.Processes {
    36  		if p.Pid == InitFriendlyName {
    37  			pid = p.SystemPid
    38  		}
    39  	}
    40  	return pid
    41  }
    42  
    43  func convertRlimits(sr []specs.Rlimit) (cr []*containerd.Rlimit) {
    44  	for _, r := range sr {
    45  		cr = append(cr, &containerd.Rlimit{
    46  			Type: r.Type,
    47  			Hard: r.Hard,
    48  			Soft: r.Soft,
    49  		})
    50  	}
    51  	return
    52  }