summaryrefslogtreecommitdiff
path: root/pkg/cgroups
diff options
context:
space:
mode:
authorKir Kolyshkin <kolyshkin@gmail.com>2020-10-05 12:33:53 -0700
committerKir Kolyshkin <kolyshkin@gmail.com>2020-10-05 15:30:37 -0700
commit4878dff3e2c89382699c29c10dc5036367275575 (patch)
tree5215fd4238ac12dc81af595d1ee3b174430769c5 /pkg/cgroups
parent1b16fcfd14b9e761849e53ac2b83c964ad8ac5a9 (diff)
downloadpodman-4878dff3e2c89382699c29c10dc5036367275575.tar.gz
podman-4878dff3e2c89382699c29c10dc5036367275575.tar.bz2
podman-4878dff3e2c89382699c29c10dc5036367275575.zip
Remove excessive error wrapping
In case os.Open[File], os.Mkdir[All], ioutil.ReadFile and the like fails, the error message already contains the file name and the operation that fails, so there is no need to wrap the error with something like "open %s failed". While at it - replace a few places with os.Open, ioutil.ReadAll with ioutil.ReadFile. - replace errors.Wrapf with errors.Wrap for cases where there are no %-style arguments. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Diffstat (limited to 'pkg/cgroups')
-rw-r--r--pkg/cgroups/cgroups.go12
-rw-r--r--pkg/cgroups/cgroups_supported.go2
-rw-r--r--pkg/cgroups/cpu.go2
3 files changed, 8 insertions, 8 deletions
diff --git a/pkg/cgroups/cgroups.go b/pkg/cgroups/cgroups.go
index f23787bd4..3cf736bdc 100644
--- a/pkg/cgroups/cgroups.go
+++ b/pkg/cgroups/cgroups.go
@@ -131,7 +131,7 @@ func getAvailableControllers(exclude map[string]controllerHandler, cgroup2 bool)
infos, err := ioutil.ReadDir(cgroupRoot)
if err != nil {
- return nil, errors.Wrapf(err, "read directory %s", cgroupRoot)
+ return nil, err
}
controllers := []controller{}
for _, i := range infos {
@@ -157,7 +157,7 @@ func (c *CgroupControl) getCgroupv1Path(name string) string {
func createCgroupv2Path(path string) (deferredError error) {
content, err := ioutil.ReadFile("/sys/fs/cgroup/cgroup.controllers")
if err != nil {
- return errors.Wrapf(err, "read /sys/fs/cgroup/cgroup.controllers")
+ return err
}
if !strings.HasPrefix(path, "/sys/fs/cgroup/") {
return fmt.Errorf("invalid cgroup path %s", path)
@@ -180,7 +180,7 @@ func createCgroupv2Path(path string) (deferredError error) {
if i > 0 {
if err := os.Mkdir(current, 0755); err != nil {
if !os.IsExist(err) {
- return errors.Wrapf(err, "mkdir %s", path)
+ return err
}
} else {
// If the directory was created, be sure it is not left around on errors.
@@ -237,7 +237,7 @@ func (c *CgroupControl) initialize() (err error) {
}
path := c.getCgroupv1Path(ctr.name)
if err := os.MkdirAll(path, 0755); err != nil {
- return errors.Wrapf(err, "error creating cgroup path %s for %s", path, ctr.name)
+ return errors.Wrapf(err, "error creating cgroup path for %s", ctr.name)
}
}
}
@@ -265,7 +265,7 @@ func (c *CgroupControl) createCgroupDirectory(controller string) (bool, error) {
func readFileAsUint64(path string) (uint64, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
- return 0, errors.Wrapf(err, "open %s", path)
+ return 0, err
}
v := cleanString(string(data))
if v == "max" {
@@ -425,7 +425,7 @@ func rmDirRecursively(path string) error {
}
entries, err := ioutil.ReadDir(path)
if err != nil {
- return errors.Wrapf(err, "read %s", path)
+ return err
}
for _, i := range entries {
if i.IsDir() {
diff --git a/pkg/cgroups/cgroups_supported.go b/pkg/cgroups/cgroups_supported.go
index a9fef38b9..fe17db7f7 100644
--- a/pkg/cgroups/cgroups_supported.go
+++ b/pkg/cgroups/cgroups_supported.go
@@ -46,7 +46,7 @@ func UserOwnsCurrentSystemdCgroup() (bool, error) {
f, err := os.Open("/proc/self/cgroup")
if err != nil {
- return false, errors.Wrapf(err, "open file /proc/self/cgroup")
+ return false, err
}
defer f.Close()
diff --git a/pkg/cgroups/cpu.go b/pkg/cgroups/cpu.go
index 3745c6e50..a73187dc8 100644
--- a/pkg/cgroups/cpu.go
+++ b/pkg/cgroups/cpu.go
@@ -134,7 +134,7 @@ func GetSystemCPUUsage() (uint64, error) {
files, err := ioutil.ReadDir(cgroupRoot)
if err != nil {
- return 0, errors.Wrapf(err, "read directory %q", cgroupRoot)
+ return 0, err
}
var total uint64
for _, file := range files {