@@ -19,6 +19,8 @@ package v2
1919import (
2020 "bufio"
2121 "context"
22+ "errors"
23+ "fmt"
2224 "io/ioutil"
2325 "math"
2426 "os"
@@ -29,10 +31,10 @@ import (
2931 "time"
3032
3133 "github.com/containerd/cgroups/v2/stats"
34+
3235 systemdDbus "github.com/coreos/go-systemd/v22/dbus"
3336 "github.com/godbus/dbus/v5"
3437 "github.com/opencontainers/runtime-spec/specs-go"
35- "github.com/pkg/errors"
3638 "github.com/sirupsen/logrus"
3739 "golang.org/x/sys/unix"
3840)
@@ -271,7 +273,7 @@ func (c *Manager) ToggleControllers(controllers []string, t ControllerToggle) er
271273 // When running as rootless, the user may face EPERM on parent groups, but it is neglible when the
272274 // controller is already written.
273275 // So we only return the last error.
274- lastErr = errors . Wrapf ( err , "failed to write subtree controllers %+v to %q" , controllers , filePath )
276+ lastErr = fmt . Errorf ( "failed to write subtree controllers %+v to %q: %w " , controllers , filePath , err )
275277 } else {
276278 lastErr = nil
277279 }
@@ -526,7 +528,7 @@ func readKVStatsFile(path string, file string, out map[string]interface{}) error
526528 for s .Scan () {
527529 name , value , err := parseKV (s .Text ())
528530 if err != nil {
529- return errors . Wrapf ( err , "error while parsing %s (line=%q)" , filepath .Join (path , file ), s .Text ())
531+ return fmt . Errorf ( "error while parsing %s (line=%q): %w " , filepath .Join (path , file ), s .Text (), err )
530532 }
531533 out [name ] = value
532534 }
@@ -563,12 +565,12 @@ func (c *Manager) MemoryEventFD() (int, uint32, error) {
563565 fpath := filepath .Join (c .path , "memory.events" )
564566 fd , err := syscall .InotifyInit ()
565567 if err != nil {
566- return 0 , 0 , errors .Errorf ( "Failed to create inotify fd" )
568+ return 0 , 0 , errors .New ( "failed to create inotify fd" )
567569 }
568570 wd , err := syscall .InotifyAddWatch (fd , fpath , unix .IN_MODIFY )
569571 if wd < 0 {
570572 syscall .Close (fd )
571- return 0 , 0 , errors .Errorf ("Failed to add inotify watch for %q" , fpath )
573+ return 0 , 0 , fmt .Errorf ("failed to add inotify watch for %q" , fpath )
572574 }
573575
574576 return fd , uint32 (wd ), nil
@@ -607,35 +609,35 @@ func (c *Manager) waitForEvents(ec chan<- Event, errCh chan<- error) {
607609 if v , ok := out ["high" ]; ok {
608610 e .High , ok = v .(uint64 )
609611 if ! ok {
610- errCh <- errors .Errorf ("cannot convert high to uint64: %+v" , v )
612+ errCh <- fmt .Errorf ("cannot convert high to uint64: %+v" , v )
611613 return
612614 }
613615 }
614616 if v , ok := out ["low" ]; ok {
615617 e .Low , ok = v .(uint64 )
616618 if ! ok {
617- errCh <- errors .Errorf ("cannot convert low to uint64: %+v" , v )
619+ errCh <- fmt .Errorf ("cannot convert low to uint64: %+v" , v )
618620 return
619621 }
620622 }
621623 if v , ok := out ["max" ]; ok {
622624 e .Max , ok = v .(uint64 )
623625 if ! ok {
624- errCh <- errors .Errorf ("cannot convert max to uint64: %+v" , v )
626+ errCh <- fmt .Errorf ("cannot convert max to uint64: %+v" , v )
625627 return
626628 }
627629 }
628630 if v , ok := out ["oom" ]; ok {
629631 e .OOM , ok = v .(uint64 )
630632 if ! ok {
631- errCh <- errors .Errorf ("cannot convert oom to uint64: %+v" , v )
633+ errCh <- fmt .Errorf ("cannot convert oom to uint64: %+v" , v )
632634 return
633635 }
634636 }
635637 if v , ok := out ["oom_kill" ]; ok {
636638 e .OOMKill , ok = v .(uint64 )
637639 if ! ok {
638- errCh <- errors .Errorf ("cannot convert oom_kill to uint64: %+v" , v )
640+ errCh <- fmt .Errorf ("cannot convert oom_kill to uint64: %+v" , v )
639641 return
640642 }
641643 }
@@ -658,7 +660,7 @@ func setDevices(path string, devices []specs.LinuxDeviceCgroup) error {
658660 }
659661 dirFD , err := unix .Open (path , unix .O_DIRECTORY | unix .O_RDONLY , 0600 )
660662 if err != nil {
661- return errors .Errorf ("cannot get dir FD for %s" , path )
663+ return fmt .Errorf ("cannot get dir FD for %s" , path )
662664 }
663665 defer unix .Close (dirFD )
664666 if _ , err := LoadAttachCgroupDeviceFilter (insts , license , dirFD ); err != nil {
0 commit comments