Skip to content

Commit

Permalink
Merge pull request #94 from coroot/init_dont_ignore_errors
Browse files Browse the repository at this point in the history
init: don't ignore errors
  • Loading branch information
apetruhin authored Jun 3, 2024
2 parents cd29567 + 0607a53 commit c05a6a0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 5 additions & 3 deletions ebpftracer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand All @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions proc/fd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"path"
"strconv"
"strings"

"k8s.io/klog/v2"
)

type Fd struct {
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions proc/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c05a6a0

Please sign in to comment.