Skip to content

Commit 93fbdb6

Browse files
committed
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 <[email protected]>
1 parent 6150ebf commit 93fbdb6

14 files changed

+28
-63
lines changed

daemon/archive.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (daemon *Daemon) CopyOnBuild(cID, destPath, srcRoot, srcPath string, decomp
375375

376376
destExists := true
377377
destDir := false
378-
rootIDs, _ := daemon.idMappings.RootPair()
378+
rootIDs := daemon.idMappings.RootPair()
379379

380380
// Work in daemon-local OS specific file paths
381381
destPath = filepath.FromSlash(destPath)

daemon/container_operations_unix.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
109109
}
110110
c.ShmPath = "/dev/shm"
111111
} else {
112-
rootIDs, _ := daemon.idMappings.RootPair()
112+
rootIDs := daemon.idMappings.RootPair()
113113
if !c.HasMountFor("/dev/shm") {
114114
shmPath, err := c.ShmResourcePath()
115115
if err != nil {
@@ -147,7 +147,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
147147
logrus.Debugf("secrets: setting up secret dir: %s", localMountPath)
148148

149149
// retrieve possible remapped range start for root UID, GID
150-
rootIDs, _ := daemon.idMappings.RootPair()
150+
rootIDs := daemon.idMappings.RootPair()
151151
// create tmpfs
152152
if err := idtools.MkdirAllAndChown(localMountPath, 0700, rootIDs); err != nil {
153153
return errors.Wrap(err, "error creating secret local mount path")
@@ -232,7 +232,7 @@ func (daemon *Daemon) setupConfigDir(c *container.Container) (setupErr error) {
232232
logrus.Debugf("configs: setting up config dir: %s", localPath)
233233

234234
// retrieve possible remapped range start for root UID, GID
235-
rootIDs, _ := daemon.idMappings.RootPair()
235+
rootIDs := daemon.idMappings.RootPair()
236236
// create tmpfs
237237
if err := idtools.MkdirAllAndChown(localPath, 0700, rootIDs); err != nil {
238238
return errors.Wrap(err, "error creating config dir")

daemon/create.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
117117
return nil, err
118118
}
119119

120-
rootIDs, err := daemon.idMappings.RootPair()
121-
if err != nil {
122-
return nil, err
123-
}
120+
rootIDs := daemon.idMappings.RootPair()
124121
if err := idtools.MkdirAndChown(container.Root, 0700, rootIDs); err != nil {
125122
return nil, err
126123
}

daemon/create_unix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (daemon *Daemon) createContainerPlatformSpecificSettings(container *contain
2222
}
2323
defer daemon.Unmount(container)
2424

25-
rootIDs, _ := daemon.idMappings.RootPair()
25+
rootIDs := daemon.idMappings.RootPair()
2626
if err := container.SetupWorkingDirectory(rootIDs); err != nil {
2727
return err
2828
}

daemon/daemon.go

+3-16
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,7 @@ func NewDaemon(config *config.Config, registryService registry.Service, containe
527527
if err != nil {
528528
return nil, err
529529
}
530-
rootIDs, err := idMappings.RootPair()
531-
if err != nil {
532-
return nil, err
533-
}
534-
530+
rootIDs := idMappings.RootPair()
535531
if err := setupDaemonProcess(config); err != nil {
536532
return nil, err
537533
}
@@ -994,7 +990,7 @@ func prepareTempDir(rootDir string, rootIDs idtools.IDPair) (string, error) {
994990
}
995991

996992
func (daemon *Daemon) setupInitLayer(initPath string) error {
997-
rootIDs, _ := daemon.idMappings.RootPair()
993+
rootIDs := daemon.idMappings.RootPair()
998994
return initlayer.Setup(initPath, rootIDs)
999995
}
1000996

@@ -1157,14 +1153,5 @@ func CreateDaemonRoot(config *config.Config) error {
11571153
if err != nil {
11581154
return err
11591155
}
1160-
rootIDs, err := idMappings.RootPair()
1161-
if err != nil {
1162-
return err
1163-
}
1164-
1165-
if err := setupDaemonRoot(config, realRoot, rootIDs); err != nil {
1166-
return err
1167-
}
1168-
1169-
return nil
1156+
return setupDaemonRoot(config, realRoot, idMappings.RootPair())
11701157
}

daemon/graphdriver/vfs/driver.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
2828
home: home,
2929
idMappings: idtools.NewIDMappingsFromMaps(uidMaps, gidMaps),
3030
}
31-
rootIDs, err := d.idMappings.RootPair()
32-
if err != nil {
33-
return nil, err
34-
}
31+
rootIDs := d.idMappings.RootPair()
3532
if err := idtools.MkdirAllAndChown(home, 0700, rootIDs); err != nil {
3633
return nil, err
3734
}
@@ -79,10 +76,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
7976
}
8077

8178
dir := d.dir(id)
82-
rootIDs, err := d.idMappings.RootPair()
83-
if err != nil {
84-
return err
85-
}
79+
rootIDs := d.idMappings.RootPair()
8680
if err := idtools.MkdirAllAndChown(filepath.Dir(dir), 0700, rootIDs); err != nil {
8781
return err
8882
}

daemon/info.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
7272
if selinuxEnabled() {
7373
securityOptions = append(securityOptions, "name=selinux")
7474
}
75-
rootIDs, _ := daemon.idMappings.RootPair()
75+
rootIDs := daemon.idMappings.RootPair()
7676
if rootIDs.UID != 0 || rootIDs.GID != 0 {
7777
securityOptions = append(securityOptions, "name=userns")
7878
}

daemon/oci_linux.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
611611
Path: c.BaseFS,
612612
Readonly: c.HostConfig.ReadonlyRootfs,
613613
}
614-
rootIDs, _ := daemon.idMappings.RootPair()
615-
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
614+
if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
616615
return err
617616
}
618617
cwd := c.Config.WorkingDir

daemon/oci_solaris.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ func (daemon *Daemon) populateCommonSpec(s *specs.Spec, c *container.Container)
130130
Path: filepath.Dir(c.BaseFS),
131131
Readonly: c.HostConfig.ReadonlyRootfs,
132132
}
133-
rootIDs, _ := daemon.idMappings.RootPair()
134-
if err := c.SetupWorkingDirectory(rootIDs); err != nil {
133+
if err := c.SetupWorkingDirectory(daemon.idMappings.RootPair()); err != nil {
135134
return err
136135
}
137136
cwd := c.Config.WorkingDir

daemon/volumes_unix.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
5454
return nil
5555
}
5656

57-
rootIDs, _ := daemon.idMappings.RootPair()
58-
path, err := m.Setup(c.MountLabel, rootIDs, checkfunc)
57+
path, err := m.Setup(c.MountLabel, daemon.idMappings.RootPair(), checkfunc)
5958
if err != nil {
6059
return nil, err
6160
}
@@ -85,7 +84,7 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
8584
// if we are going to mount any of the network files from container
8685
// metadata, the ownership must be set properly for potential container
8786
// remapped root (user namespaces)
88-
rootIDs, _ := daemon.idMappings.RootPair()
87+
rootIDs := daemon.idMappings.RootPair()
8988
for _, mount := range netMounts {
9089
if err := os.Chown(mount.Source, rootIDs.UID, rootIDs.GID); err != nil {
9190
return nil, err

daemon/workdir.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ func (daemon *Daemon) ContainerCreateWorkdir(cID string) error {
1616
return err
1717
}
1818
defer daemon.Unmount(container)
19-
rootIDs, _ := daemon.idMappings.RootPair()
20-
return container.SetupWorkingDirectory(rootIDs)
19+
return container.SetupWorkingDirectory(daemon.idMappings.RootPair())
2120
}

pkg/archive/archive.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -803,10 +803,7 @@ func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) err
803803

804804
var dirs []*tar.Header
805805
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
806-
rootIDs, err := idMappings.RootPair()
807-
if err != nil {
808-
return err
809-
}
806+
rootIDs := idMappings.RootPair()
810807
whiteoutConverter := getWhiteoutConverter(options.WhiteoutFormat)
811808

812809
// Iterate through the files in the archive.
@@ -1008,10 +1005,7 @@ func (archiver *Archiver) CopyWithTar(src, dst string) error {
10081005
// if this archiver is set up with ID mapping we need to create
10091006
// the new destination directory with the remapped root UID/GID pair
10101007
// as owner
1011-
rootIDs, err := archiver.IDMappings.RootPair()
1012-
if err != nil {
1013-
return err
1014-
}
1008+
rootIDs := archiver.IDMappings.RootPair()
10151009
// Create dst, copy src's content into it
10161010
logrus.Debugf("Creating dest directory: %s", dst)
10171011
if err := idtools.MkdirAllAndChownNew(dst, 0755, rootIDs); err != nil {

pkg/chrootarchive/archive.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ func untarHandler(tarArchive io.Reader, dest string, options *archive.TarOptions
4747
}
4848

4949
idMappings := idtools.NewIDMappingsFromMaps(options.UIDMaps, options.GIDMaps)
50-
rootIDs, err := idMappings.RootPair()
51-
if err != nil {
52-
return err
53-
}
50+
rootIDs := idMappings.RootPair()
5451

5552
dest = filepath.Clean(dest)
5653
if _, err := os.Stat(dest); os.IsNotExist(err) {

pkg/idtools/idtools.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,19 @@ func NewIDMappingsFromMaps(uids []IDMap, gids []IDMap) *IDMappings {
158158
return &IDMappings{uids: uids, gids: gids}
159159
}
160160

161-
// RootPair returns a uid and gid pair for the root user
162-
func (i *IDMappings) RootPair() (IDPair, error) {
163-
uid, gid, err := GetRootUIDGID(i.uids, i.gids)
164-
return IDPair{UID: uid, GID: gid}, err
161+
// RootPair returns a uid and gid pair for the root user. The error is ignored
162+
// because a root user always exists, and the defaults are correct when the uid
163+
// and gid maps are empty.
164+
func (i *IDMappings) RootPair() IDPair {
165+
uid, gid, _ := GetRootUIDGID(i.uids, i.gids)
166+
return IDPair{UID: uid, GID: gid}
165167
}
166168

167169
// ToHost returns the host UID and GID for the container uid, gid.
168170
// Remapping is only performed if the ids aren't already the remapped root ids
169171
func (i *IDMappings) ToHost(pair IDPair) (IDPair, error) {
170-
target, err := i.RootPair()
171-
if err != nil {
172-
return IDPair{}, err
173-
}
172+
var err error
173+
target := i.RootPair()
174174

175175
if pair.UID != target.UID {
176176
target.UID, err = toHost(pair.UID, i.uids)

0 commit comments

Comments
 (0)