diff --git a/containers/container.go b/containers/container.go index 3c78d41..df5a063 100644 --- a/containers/container.go +++ b/containers/container.go @@ -1024,6 +1024,7 @@ func (c *Container) revalidateListens(now time.Time, actualListens map[netaddr.I for pid := range c.processes { fds, err := proc.ReadFds(pid) if err != nil { + klog.Warningln(err) continue } for _, fd := range fds { diff --git a/ebpftracer/init.go b/ebpftracer/init.go index 9c0636f..0f6febe 100644 --- a/ebpftracer/init.go +++ b/ebpftracer/init.go @@ -23,17 +23,18 @@ func readFds(pids []uint32) (files []file, socks []sock) { for _, pid := range pids { ns, err := proc.GetNetNs(pid) if err != nil { + klog.Warningf("failed to get net ns for %d: %s", pid, err) continue } nsId := ns.UniqueId() sockets, ok := nss[nsId] _ = ns.Close() if !ok { - sockets = map[string]sock{} - nss[nsId] = sockets if ss, err := proc.GetSockets(pid); err != nil { - klog.Warningln(err) + klog.Warningf("failed to get sockets for %d: %s", pid, err) } else { + sockets = map[string]sock{} + nss[nsId] = sockets for _, s := range ss { sockets[s.Inode] = sock{Sock: s} } @@ -42,6 +43,7 @@ func readFds(pids []uint32) (files []file, socks []sock) { fds, err := proc.ReadFds(pid) if err != nil { + klog.Warningf("failed to read fds for %d: %s", pid, err) continue } for _, fd := range fds { diff --git a/proc/fd.go b/proc/fd.go index 78d831c..5b294ea 100644 --- a/proc/fd.go +++ b/proc/fd.go @@ -5,6 +5,8 @@ import ( "path" "strconv" "strings" + + "k8s.io/klog/v2" ) type Fd struct { @@ -18,16 +20,23 @@ func ReadFds(pid uint32) ([]Fd, error) { fdDir := Path(pid, "fd") entries, err := os.ReadDir(fdDir) if err != nil { + if os.IsNotExist(err) { + return nil, nil + } return nil, err } res := make([]Fd, 0, len(entries)) for _, entry := range entries { fd, err := strconv.ParseUint(entry.Name(), 10, 64) if err != nil { + klog.Warningf("failed to parse fd '%s': %s", entry.Name(), err) continue } dest, err := os.Readlink(path.Join(fdDir, entry.Name())) if err != nil { + if os.IsNotExist(err) { + klog.Warningf("failed to read link '%s': %s", entry.Name(), err) + } continue } var socketInode string diff --git a/proc/net.go b/proc/net.go index c367cfd..70d6039 100644 --- a/proc/net.go +++ b/proc/net.go @@ -39,6 +39,9 @@ func GetSockets(pid uint32) ([]Sock, error) { func readSockets(src string) ([]Sock, error) { f, err := os.Open(src) if err != nil { + if os.IsNotExist(err) { + return nil, nil + } return nil, err } defer f.Close()