Fix fs error handling

This commit is contained in:
Daniel
2022-10-11 14:49:06 +02:00
parent b53b77e28c
commit 1144ac589b
8 changed files with 25 additions and 16 deletions

View File

@@ -3,7 +3,9 @@
package proc
import (
"errors"
"fmt"
"io/fs"
"os"
"time"
@@ -103,7 +105,7 @@ func findSocketFromPid(pid int, socketName string) bool {
for _, entry := range entries {
link, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%s", pid, entry))
if err != nil {
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
log.Warningf("proc: failed to read link /proc/%d/fd/%s: %s", pid, entry, err)
}
continue
@@ -122,7 +124,7 @@ func findSocketFromPid(pid int, socketName string) bool {
func readDirNames(dir string) (names []string) {
file, err := os.Open(dir)
if err != nil {
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
log.Warningf("proc: could not open directory %s: %s", dir, err)
}
return

View File

@@ -3,7 +3,9 @@
package proc
import (
"errors"
"fmt"
"io/fs"
"os"
"strconv"
"sync"
@@ -50,7 +52,7 @@ func updatePids() {
statData, err := os.Stat(fmt.Sprintf("/proc/%d", pid))
if err != nil {
if !os.IsNotExist(err) {
if !errors.Is(err, fs.ErrNotExist) {
log.Warningf("proc: could not stat /proc/%d: %s", pid, err)
}
continue entryLoop