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