From 4359978ef22a22ddd5a19adf18cbc80cb44244fb Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Thu, 23 Feb 2023 14:28:18 +0100 Subject: all: ioutil is deprecated in go1.19 (#3718) --- pkg/host/machine_info_linux.go | 9 ++++----- pkg/host/syscalls_linux.go | 7 +++---- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'pkg/host') diff --git a/pkg/host/machine_info_linux.go b/pkg/host/machine_info_linux.go index fb05382ba..fc3664c42 100644 --- a/pkg/host/machine_info_linux.go +++ b/pkg/host/machine_info_linux.go @@ -7,7 +7,6 @@ import ( "bufio" "bytes" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -86,7 +85,7 @@ func allEqual(slice []string) bool { } func readKVMInfo(buffer *bytes.Buffer) error { - files, err := ioutil.ReadDir("/sys/module/") + files, err := os.ReadDir("/sys/module/") if err != nil { return err } @@ -98,7 +97,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { } paramPath := filepath.Join("/sys", "module", name, "parameters") - params, err := ioutil.ReadDir(paramPath) + params, err := os.ReadDir(paramPath) if err != nil { if os.IsNotExist(err) { continue @@ -113,7 +112,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { fmt.Fprintf(buffer, "/sys/module/%s:\n", name) for _, key := range params { keyName := key.Name() - data, err := ioutil.ReadFile(filepath.Join(paramPath, keyName)) + data, err := os.ReadFile(filepath.Join(paramPath, keyName)) if err != nil { return err } @@ -127,7 +126,7 @@ func readKVMInfo(buffer *bytes.Buffer) error { func getModulesInfo() ([]KernelModule, error) { var modules []KernelModule - modulesText, _ := ioutil.ReadFile("/proc/modules") + modulesText, _ := os.ReadFile("/proc/modules") re := regexp.MustCompile(`(\w+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`) for _, m := range re.FindAllSubmatch(modulesText, -1) { addr, err := strconv.ParseUint(string(m[2]), 0, 64) diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index 6425fcce7..67efd9295 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -6,7 +6,6 @@ package host import ( "bytes" "fmt" - "io/ioutil" "os" "regexp" "runtime" @@ -58,7 +57,7 @@ func isSupportedSyscall(c *prog.Syscall, target *prog.Target) (bool, string) { // Kallsyms seems to be the most reliable and fast. That's what we use first. // If kallsyms is not present, we fallback to execution of syscalls. kallsymsOnce.Do(func() { - kallsyms, _ := ioutil.ReadFile("/proc/kallsyms") + kallsyms, _ := os.ReadFile("/proc/kallsyms") if len(kallsyms) == 0 { return } @@ -390,7 +389,7 @@ func isSupportedSyzOpenDev(sandbox string, c *prog.Syscall) (bool, string) { func isSupportedLSM(c *prog.Syscall) string { lsmOnce.Do(func() { - data, err := ioutil.ReadFile("/sys/kernel/security/lsm") + data, err := os.ReadFile("/sys/kernel/security/lsm") if err != nil { // securityfs may not be mounted, but it does not mean // that no LSMs are enabled. @@ -522,7 +521,7 @@ func isSupportedMount(c *prog.Syscall, sandbox string) (bool, string) { func isSupportedFilesystem(fstype string) (bool, string) { filesystemsOnce.Do(func() { - filesystems, _ = ioutil.ReadFile("/proc/filesystems") + filesystems, _ = os.ReadFile("/proc/filesystems") }) if !bytes.Contains(filesystems, []byte("\t"+fstype+"\n")) { return false, fmt.Sprintf("/proc/filesystems does not contain %v", fstype) -- cgit mrf-deployment