Refactors getRootIDs

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2016-02-25 11:23:37 -08:00
parent 3856e27560
commit 817c2089aa
6 changed files with 68 additions and 23 deletions

View file

@ -246,14 +246,14 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro
return p, nil
}
func (c *container) readSpec() (*specs.LinuxSpec, error) {
var spec specs.LinuxSpec
func (c *container) readSpec() (*platformSpec, error) {
var spec platformSpec
f, err := os.Open(filepath.Join(c.bundle, "config.json"))
if err != nil {
return nil, err
}
defer f.Close()
if err := json.NewDecoder(f).Decode(&spec); err != nil {
if err := json.NewDecoder(f).Decode(&spec.Spec); err != nil {
return nil, err
}
return &spec, nil
@ -389,25 +389,6 @@ func (c *container) getLibctContainer() (libcontainer.Container, error) {
return f.Load(c.id)
}
func getRootIDs(s *specs.LinuxSpec) (int, int, error) {
if s == nil {
return 0, 0, nil
}
var hasUserns bool
for _, ns := range s.Linux.Namespaces {
if ns.Type == specs.UserNamespace {
hasUserns = true
break
}
}
if !hasUserns {
return 0, 0, nil
}
uid := hostIDFromMap(0, s.Linux.UIDMappings)
gid := hostIDFromMap(0, s.Linux.GIDMappings)
return uid, gid, nil
}
func hostIDFromMap(id uint32, mp []specs.IDMapping) int {
for _, m := range mp {
if (id >= m.ContainerID) && (id <= (m.ContainerID + m.Size - 1)) {