libct/cgroups/fs2: use errors.Unwrap

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-03-31 19:57:26 -07:00
parent e4e35b8de8
commit d2dfc635ea
1 changed files with 1 additions and 11 deletions

View File

@ -4,7 +4,6 @@ package fs2
import ( import (
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -25,20 +24,11 @@ func setPids(dirPath string, cgroup *configs.Cgroup) error {
return nil return nil
} }
func isNOTSUP(err error) bool {
switch err := err.(type) {
case *os.PathError:
return err.Err == unix.ENOTSUP
default:
return false
}
}
func statPidsWithoutController(dirPath string, stats *cgroups.Stats) error { func statPidsWithoutController(dirPath string, stats *cgroups.Stats) error {
// if the controller is not enabled, let's read PIDS from cgroups.procs // if the controller is not enabled, let's read PIDS from cgroups.procs
// (or threads if cgroup.threads is enabled) // (or threads if cgroup.threads is enabled)
contents, err := ioutil.ReadFile(filepath.Join(dirPath, "cgroup.procs")) contents, err := ioutil.ReadFile(filepath.Join(dirPath, "cgroup.procs"))
if err != nil && isNOTSUP(err) { if err != nil && errors.Unwrap(err) == unix.ENOTSUP {
contents, err = ioutil.ReadFile(filepath.Join(dirPath, "cgroup.threads")) contents, err = ioutil.ReadFile(filepath.Join(dirPath, "cgroup.threads"))
} }
if err != nil { if err != nil {