From 407c5e46512b5ca7260310e898f9d2558e224b92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 3 Jul 2024 10:54:07 +0200 Subject: [PATCH 1/4] Fix errcheck: error return value of `snapshot.Destroy` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/zfs/zfs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/zfs/zfs.go b/drivers/zfs/zfs.go index 5a7b2da7b0..0e859a93b8 100644 --- a/drivers/zfs/zfs.go +++ b/drivers/zfs/zfs.go @@ -240,7 +240,9 @@ func (d *Driver) cloneFilesystem(name, parentName string) error { } if err != nil { - snapshot.Destroy(zfs.DestroyDeferDeletion) + if err1 := snapshot.Destroy(zfs.DestroyDeferDeletion); err1 != nil { + logrus.Warnf("Destroy zfs.DestroyDeferDeletion: %v", err1) + } return err } return snapshot.Destroy(zfs.DestroyDeferDeletion) From 4485ffa7a66b422c44d96e3e2da7dc708a2c1005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 3 Jul 2024 13:00:49 +0200 Subject: [PATCH 2/4] Fix errcheck: error return value of `unix.Unmount` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/overlay/check.go | 6 +++++- drivers/overlay/overlay.go | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/overlay/check.go b/drivers/overlay/check.go index d8139f6566..d75c5fdf5e 100644 --- a/drivers/overlay/check.go +++ b/drivers/overlay/check.go @@ -263,7 +263,11 @@ func supportsIdmappedLowerLayers(home string) (bool, error) { if err := idmap.CreateIDMappedMount(lowerDir, lowerMappedDir, int(pid)); err != nil { return false, fmt.Errorf("create mapped mount: %w", err) } - defer unix.Unmount(lowerMappedDir, unix.MNT_DETACH) + defer func() { + if err := unix.Unmount(lowerMappedDir, unix.MNT_DETACH); err != nil { + logrus.Warnf("Unmount %q: %v", lowerMappedDir, err) + } + }() opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", lowerMappedDir, upperDir, workDir) flags := uintptr(0) diff --git a/drivers/overlay/overlay.go b/drivers/overlay/overlay.go index 78aeff404d..2f33ddea60 100644 --- a/drivers/overlay/overlay.go +++ b/drivers/overlay/overlay.go @@ -1555,7 +1555,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO composefsMounts := []string{} defer func() { for _, m := range composefsMounts { - defer unix.Unmount(m, unix.MNT_DETACH) + defer func(m string) { + if err := unix.Unmount(m, unix.MNT_DETACH); err != nil { + logrus.Warnf("Unmount %q: %v", m, err) + } + }(m) } }() @@ -1659,7 +1663,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO skipIDMappingLayers[composefsMount] = composefsMount // overlay takes a reference on the mount, so it is safe to unmount // the mapped idmounts as soon as the final overlay file system is mounted. - defer unix.Unmount(composefsMount, unix.MNT_DETACH) + defer func() { + if err := unix.Unmount(composefsMount, unix.MNT_DETACH); err != nil { + logrus.Warnf("Unmount %q: %v", composefsMount, err) + } + }() } absLowers = append(absLowers, composefsMount) continue @@ -1766,7 +1774,11 @@ func (d *Driver) get(id string, disableShifting bool, options graphdriver.MountO // overlay takes a reference on the mount, so it is safe to unmount // the mapped idmounts as soon as the final overlay file system is mounted. - defer unix.Unmount(root, unix.MNT_DETACH) + defer func() { + if err := unix.Unmount(root, unix.MNT_DETACH); err != nil { + logrus.Warnf("Unmount %q: %v", root, err) + } + }() } // relative path to the layer through the id mapped mount From 63ee316cb08273315f6cf8e1914b8f47dda74684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 3 Jul 2024 14:05:55 +0200 Subject: [PATCH 3/4] Ignore errcheck: error return value of `system.Umask` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- pkg/archive/archive_linux_test.go | 12 ++++++++---- pkg/chrootarchive/diff_unix.go | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pkg/archive/archive_linux_test.go b/pkg/archive/archive_linux_test.go index 9b56b3752f..dc0de1851c 100644 --- a/pkg/archive/archive_linux_test.go +++ b/pkg/archive/archive_linux_test.go @@ -93,9 +93,11 @@ func checkFileMode(t *testing.T, path string, perm os.FileMode) { } func TestOverlayTarUntar(t *testing.T) { - oldmask, err := system.Umask(0) + oldMask, err := system.Umask(0) require.NoError(t, err) - defer system.Umask(oldmask) + defer func() { + _, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above. + }() src := t.TempDir() setupOverlayTestDir(t, src) @@ -131,9 +133,11 @@ func TestOverlayTarUntar(t *testing.T) { } func TestOverlayTarAUFSUntar(t *testing.T) { - oldmask, err := system.Umask(0) + oldMask, err := system.Umask(0) require.NoError(t, err) - defer system.Umask(oldmask) + defer func() { + _, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above. + }() src := t.TempDir() setupOverlayTestDir(t, src) diff --git a/pkg/chrootarchive/diff_unix.go b/pkg/chrootarchive/diff_unix.go index 71ed094d1e..cdcd9fdc3b 100644 --- a/pkg/chrootarchive/diff_unix.go +++ b/pkg/chrootarchive/diff_unix.go @@ -40,11 +40,13 @@ func applyLayer() { } // We need to be able to set any perms - oldmask, err := system.Umask(0) - defer system.Umask(oldmask) + oldMask, err := system.Umask(0) if err != nil { fatal(err) } + defer func() { + _, _ = system.Umask(oldMask) // Ignore err. This can only fail with ErrNotSupportedPlatform, in which case we would have failed above. + }() if err := json.Unmarshal([]byte(os.Getenv("OPT")), &options); err != nil { fatal(err) From 55ccf47a7f4eaaac6733367acd1cdd617fbb48fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Wed, 3 Jul 2024 14:15:24 +0200 Subject: [PATCH 4/4] Fix errcheck: error return value of `aufs.Unmount` is not checked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Rodák --- drivers/aufs/aufs.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/aufs/aufs.go b/drivers/aufs/aufs.go index 8051dddb21..91eb32f123 100644 --- a/drivers/aufs/aufs.go +++ b/drivers/aufs/aufs.go @@ -683,7 +683,9 @@ func (a *Driver) Cleanup() error { func (a *Driver) aufsMount(ro []string, rw, target string, options graphdriver.MountOpts) (err error) { defer func() { if err != nil { - Unmount(target) + if err1 := Unmount(target); err1 != nil { + logrus.Warnf("Unmount %q: %v", target, err1) + } } }()