// TODO(vmarmol): Switch to getting this from libcontainer once we have a solid API. func (self *dockerContainerHandler) readLibcontainerConfig() (*libcontainer.Config, error) { out, err := ioutil.ReadFile(self.libcontainerConfigPath) if err != nil { return nil, fmt.Errorf("failed to read libcontainer config from %q: %v", self.libcontainerConfigPath, err) } var config libcontainer.Config err = json.Unmarshal(out, &config) if err != nil { // TODO(vmarmol): Remove this once it becomes the standard. // Try to parse the old config. The main difference is that namespaces used to be a map, now it is a slice of structs. // The JSON marshaler will use the non-nested field before the nested one. type oldLibcontainerConfig struct { libcontainer.Config OldNamespaces map[string]bool `json:"namespaces,omitempty"` } var oldConfig oldLibcontainerConfig err2 := json.Unmarshal(out, &oldConfig) if err2 != nil { // Use original error. return nil, fmt.Errorf("failed to parse libcontainer config at %q: %v", self.libcontainerConfigPath, err) } // Translate the old config into the new config. config = oldConfig.Config for ns := range oldConfig.OldNamespaces { config.Namespaces = append(config.Namespaces, libcontainer.Namespace{ Type: libcontainer.NamespaceType(ns), }) } } // Replace cgroup parent and name with our own since we may be running in a different context. config.Cgroups.Name = self.cgroup.Name config.Cgroups.Parent = self.cgroup.Parent return &config, nil }