Remove error return from RootPair

There is no case which would resolve in this error. The root user always exists, and if the id maps are empty, the default value of 0 is correct.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Upstream-commit: 93fbdb69acf9248283a91a1c5c6ea24711c26eda
Component: engine
This commit is contained in:
Daniel Nephin
2017-06-07 11:45:33 -04:00
parent b35fc7f268
commit 583893964e
14 changed files with 28 additions and 63 deletions
+1 -1
View File
@@ -375,7 +375,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp
destExists := true
destDir := false
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
// Work in daemon-local OS specific file paths
destPath = filepath.FromSlash(destPath)
@@ -109,7 +109,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
}
c.ShmPath = "/dev/shm"
} else {
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
if !c.HasMountFor("/dev/shm") {
shmPath, err := c.ShmResourcePath()
if err != nil {
@@ -147,7 +147,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
// retrieve possible remapped range start for root UID, GID
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
// create tmpfs
if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
return errors.Wrap(err, "error creating secret local mount path")
@@ -232,7 +232,7 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
logrus.Debugf("configs: setting up config dir: %s", localPath)
// retrieve possible remapped range start for root UID, GID
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
// create tmpfs
if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
return errors.Wrap(err, "error creating config dir")
+1 -4
View File
@@ -117,10 +117,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
return nil, err
}
rootIDs, err := daemon.idMappings.RootPair()
if err != nil {
return nil, err
}
rootIDs := daemon.idMappings.RootPair()
if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
return nil, err
}
+1 -1
View File
@@ -22,7 +22,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
}
defer daemon.Unmount(container)
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
if err := container.SetupWorkingDirectory(rootIDs); err != nil {
return err
}
+3 -16
View File
@@ -527,11 +527,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
if err != nil {
return nil, err
}
rootIDs, err := idMappings.RootPair()
if err != nil {
return nil, err
}
rootIDs := idMappings.RootPair()
if err := setupDaemonProcess(config); err != nil {
return nil, err
}
@@ -994,7 +990,7 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) {
}
func (daemon *Daemon) setupInitLayer(initPath string) error {
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
return initlayer.Setup(initPath, rootIDs)
}
@@ -1157,14 +1153,5 @@ func CreateDaemonRoot(config *config.Config) error {
if err != nil {
return err
}
rootIDs, err := idMappings.RootPair()
if err != nil {
return err
}
if err := setupDaemonRoot(config, realRoot, rootIDs); err != nil {
return err
}
return nil
return setupDaemonRoot(config, realRoot, idMappings.RootPair())
}
@@ -28,10 +28,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
home: home,
idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
}
rootIDs, err := d.idMappings.RootPair()
if err != nil {
return nil, err
}
rootIDs := d.idMappings.RootPair()
if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
return nil, err
}
@@ -79,10 +76,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
}
dir := d.dir(id)
rootIDs, err := d.idMappings.RootPair()
if err != nil {
return err
}
rootIDs := d.idMappings.RootPair()
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
return err
}
+1 -1
View File
@@ -72,7 +72,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
if selinuxEnabled() {
securityOptions = append(securityOptions, "name=selinux")
}
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
if rootIDs.UID != 0 || rootIDs.GID != 0 {
securityOptions = append(securityOptions, "name=userns")
}
+1 -2
View File
@@ -611,8 +611,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
Path: c.BaseFS,
Readonly: c.HostConfig.ReadonlyRootfs,
}
rootIDs, _ := daemon.idMappings.RootPair()
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
return err
}
cwd := c.Config.WorkingDir
+1 -2
View File
@@ -130,8 +130,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
Path: filepath.Dir(c.BaseFS),
Readonly: c.HostConfig.ReadonlyRootfs,
}
rootIDs, _ := daemon.idMappings.RootPair()
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
return err
}
cwd := c.Config.WorkingDir
+2 -3
View File
@@ -54,8 +54,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
return nil
}
rootIDs, _ := daemon.idMappings.RootPair()
path, err := m.Setup(c.MountLabel, rootIDs, checkfunc)
path, err := m.Setup(c.MountLabel, daemon.idMappings.RootPair(), checkfunc)
if err != nil {
return nil, err
}
@@ -85,7 +84,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
// if we are going to mount any of the network files from container
// metadata, the ownership must be set properly for potential container
// remapped root (user namespaces)
rootIDs, _ := daemon.idMappings.RootPair()
rootIDs := daemon.idMappings.RootPair()
for _, mount := range netMounts {
if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
return nil, err
+1 -2
View File
@@ -16,6 +16,5 @@ func (daemon *Daemon) ContainerCreateWorkdir(cID string) error {
return err
}
defer daemon.Unmount(container)
rootIDs, _ := daemon.idMappings.RootPair()
return container.SetupWorkingDirectory(rootIDs)
return container.SetupWorkingDirectory(daemon.idMappings.RootPair())
}
+2 -8
View File
@@ -803,10 +803,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
var dirs []*tar.Header
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
rootIDs, err := idMappings.RootPair()
if err != nil {
return err
}
rootIDs := idMappings.RootPair()
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
// Iterate through the files in the archive.
@@ -1008,10 +1005,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
// if this archiver is set up with ID mapping we need to create
// the new destination directory with the remapped root UID/GID pair
// as owner
rootIDs, err := archiver.IDMappings.RootPair()
if err != nil {
return err
}
rootIDs := archiver.IDMappings.RootPair()
// Create dst, copy src's content into it
logrus.Debugf("Creating dest directory: %s", dst)
if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {
@@ -47,10 +47,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
}
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
rootIDs, err := idMappings.RootPair()
if err != nil {
return err
}
rootIDs := idMappings.RootPair()
dest = filepath.Clean(dest)
if _, err := os.Stat(dest); os.IsNotExist(err) {
+8 -8
View File
@@ -158,19 +158,19 @@ func NewIDMappingsFromMaps(uids []IDMap, gids []IDMap) *IDMappings {
return &IDMappings{uids: uids, gids: gids}
}
// RootPair returns a uid and gid pair for the root user
func (i *IDMappings) RootPair() (IDPair, error) {
uid, gid, err := GetRootUIDGID(i.uids, i.gids)
return IDPair{UID: uid, GID: gid}, err
// RootPair returns a uid and gid pair for the root user. The error is ignored
// because a root user always exists, and the defaults are correct when the uid
// and gid maps are empty.
func (i *IDMappings) RootPair() IDPair {
uid, gid, _ := GetRootUIDGID(i.uids, i.gids)
return IDPair{UID: uid, GID: gid}
}
// ToHost returns the host UID and GID for the container uid, gid.
// Remapping is only performed if the ids aren't already the remapped root ids
func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
target, err := i.RootPair()
if err != nil {
return IDPair{}, err
}
var err error
target := i.RootPair()
if pair.UID != target.UID {
target.UID, err = toHost(pair.UID, i.uids)