libct/setKernelMemory: use errors.Unwrap
This simplifies code a lot. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
9ec5b03e5a
commit
66778b3c28
|
@ -6,10 +6,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall" // for Errno type only
|
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/cgroups"
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
@ -49,12 +47,8 @@ func setKernelMemory(path string, kernelMemoryLimit int64) error {
|
||||||
// The EBUSY signal is returned on attempts to write to the
|
// The EBUSY signal is returned on attempts to write to the
|
||||||
// memory.kmem.limit_in_bytes file if the cgroup has children or
|
// memory.kmem.limit_in_bytes file if the cgroup has children or
|
||||||
// once tasks have been attached to the cgroup
|
// once tasks have been attached to the cgroup
|
||||||
if pathErr, ok := err.(*os.PathError); ok {
|
if errors.Unwrap(err) == unix.EBUSY {
|
||||||
if errNo, ok := pathErr.Err.(syscall.Errno); ok {
|
return fmt.Errorf("failed to set %s, because either tasks have already joined this cgroup or it has children", cgroupKernelMemoryLimit)
|
||||||
if errNo == unix.EBUSY {
|
|
||||||
return fmt.Errorf("failed to set %s, because either tasks have already joined this cgroup or it has children", cgroupKernelMemoryLimit)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("failed to write %v to %v: %v", kernelMemoryLimit, cgroupKernelMemoryLimit, err)
|
return fmt.Errorf("failed to write %v to %v: %v", kernelMemoryLimit, cgroupKernelMemoryLimit, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue