diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/eventloop.go | 20 | ||||
| -rw-r--r-- | internal/eventloop_test.go | 20 | ||||
| -rw-r--r-- | internal/file/file.go | 24 |
3 files changed, 33 insertions, 31 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go index 8e336a2..26eaafc 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -211,7 +211,7 @@ type eventLoop struct { enterEvs map[uint32]*event.Pair // Temp. store of sys_enter tracepoints per Tid. pendingHandles map[uint32]string // map of TID to pathname from name_to_handle_at fdTracker *fdTracker - procFdCache map[uint64]file.FdFile // Cache procfs-resolved metadata for unknown fds. + procFdCache map[uint64]*file.FdFile // Cache procfs-resolved metadata for unknown fds. commResolver *commResolver prevPairTimes map[uint32]uint64 // Previous event's time (to calculate time differences between two events) rawHandlers map[types.EventType]rawEventHandler @@ -242,7 +242,7 @@ func newEventLoop(cfg eventLoopConfig) (*eventLoop, error) { enterEvs: make(map[uint32]*event.Pair), pendingHandles: make(map[uint32]string), fdTracker: fdState, - procFdCache: make(map[uint64]file.FdFile), + procFdCache: make(map[uint64]*file.FdFile), commResolver: commState, prevPairTimes: make(map[uint32]uint64), rawHandlers: make(map[types.EventType]rawEventHandler), @@ -668,7 +668,7 @@ func (e *eventLoop) handleFdExit(ep *event.Pair, fdEv *types.FdEvent) bool { } if ep.Is(types.SYS_ENTER_DUP) || ep.Is(types.SYS_ENTER_DUP2) { - fdFile, ok := ep.File.(file.FdFile) + fdFile, ok := ep.File.(*file.FdFile) if !ok { e.recyclePair(ep, "Dropped malformed dup source event") return false @@ -708,7 +708,7 @@ func (e *eventLoop) handleDup3Exit(ep *event.Pair, dup3Ev *types.Dup3Event) bool return false } - fdFile, ok := ep.File.(file.FdFile) + fdFile, ok := ep.File.(*file.FdFile) if !ok { e.recyclePair(ep, "Dropped malformed dup3 source event") return false @@ -805,7 +805,7 @@ func (e *eventLoop) handleFcntlExit(ep *event.Pair, fcntlEv *types.FcntlEvent) b return true } - fdFile, ok := ep.File.(file.FdFile) + fdFile, ok := ep.File.(*file.FdFile) if !ok { e.recyclePair(ep, "Dropped malformed fcntl file event") return false @@ -826,7 +826,7 @@ func (e *eventLoop) handleFcntlExit(ep *event.Pair, fcntlEv *types.FcntlEvent) b return true } -func (e *eventLoop) registerDup(fdFile file.FdFile, newFd int32, extraFlags int32) { +func (e *eventLoop) registerDup(fdFile *file.FdFile, newFd int32, extraFlags int32) { if newFd < 0 { return } @@ -867,12 +867,12 @@ func (e *eventLoop) resolveFdFile(fd int32, pid uint32) file.File { return discovered } -func (e *eventLoop) cachedProcFdFile(fd int32, pid uint32) (file.FdFile, bool) { +func (e *eventLoop) cachedProcFdFile(fd int32, pid uint32) (*file.FdFile, bool) { cache, ok := e.procFdCacheState()[procFdCacheKey(pid, fd)] return cache, ok } -func (e *eventLoop) setProcFdCache(fd int32, pid uint32, resolved file.FdFile) { +func (e *eventLoop) setProcFdCache(fd int32, pid uint32, resolved *file.FdFile) { e.procFdCacheState()[procFdCacheKey(pid, fd)] = resolved } @@ -891,9 +891,9 @@ func (e *eventLoop) deleteProcFdCacheFrom(first int32, pid uint32) { } } -func (e *eventLoop) procFdCacheState() map[uint64]file.FdFile { +func (e *eventLoop) procFdCacheState() map[uint64]*file.FdFile { if e.procFdCache == nil { - e.procFdCache = make(map[uint64]file.FdFile) + e.procFdCache = make(map[uint64]*file.FdFile) } return e.procFdCache } diff --git a/internal/eventloop_test.go b/internal/eventloop_test.go index cfc18e8..7fcd438 100644 --- a/internal/eventloop_test.go +++ b/internal/eventloop_test.go @@ -1527,7 +1527,7 @@ func makeDup3WithCloexecTestData(t *testing.T) (td testData) { // Verify the new fd has O_CLOEXEC flag if newFile, ok := el.fdState().files[newFd]; ok { - fdFile, ok := newFile.(file.FdFile) + fdFile, ok := newFile.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if !fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1612,7 +1612,7 @@ func makeDup2TestData(t *testing.T) (td testData) { // Verify the new fd does NOT have O_CLOEXEC flag (unlike dup3) if newFile, ok := el.fdState().files[targetFd]; ok { - fdFile, ok := newFile.(file.FdFile) + fdFile, ok := newFile.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1765,7 +1765,7 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { // Verify flags were updated on the file descriptor if f, ok := el.fdState().files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else { @@ -1801,7 +1801,7 @@ func makeFcntlSetFlagsTestData(t *testing.T) (td testData) { // Verify flags were updated correctly if f, ok := el.fdState().files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else { @@ -1879,7 +1879,7 @@ func makeFcntlDupfdTestData(t *testing.T) (td testData) { // Verify the new fd does NOT have O_CLOEXEC flag (F_DUPFD doesn't set it) if f, ok := el.fdState().files[int32(newFd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1963,7 +1963,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { verifyFileDescriptor(t, el, int32(origFd), filename) // Verify original fd doesn't have O_CLOEXEC if f, ok := el.fdState().files[int32(origFd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -1994,7 +1994,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { // Verify the new fd has O_CLOEXEC flag if f, ok := el.fdState().files[int32(newFd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if !fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -2004,7 +2004,7 @@ func makeFcntlDupfdCloexecTestData(t *testing.T) (td testData) { // Verify original fd still doesn't have O_CLOEXEC if f, ok := el.fdState().files[int32(origFd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_CLOEXEC) { @@ -2123,7 +2123,7 @@ func makeFcntlErrorTestData(t *testing.T) (td testData) { // Verify flags were NOT updated due to error if f, ok := el.fdState().files[int32(fd)]; ok { - fdFile, ok := f.(file.FdFile) + fdFile, ok := f.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } else if fdFile.Flags().Is(syscall.O_NONBLOCK) { @@ -2193,7 +2193,7 @@ func makeFcntlInvalidFdTestData(t *testing.T) (td testData) { if ep.File == nil { t.Errorf("Expected file to be created for invalid fd") } else { - _, ok := ep.File.(file.FdFile) + _, ok := ep.File.(*file.FdFile) if !ok { t.Errorf("Expected file to be FdFile type") } diff --git a/internal/file/file.go b/internal/file/file.go index 08e0bee..83c690a 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -25,8 +25,8 @@ type FdFile struct { flagsFromProcFS bool } -func NewFd(fd int32, name string, flags int32) FdFile { - f := FdFile{ +func NewFd(fd int32, name string, flags int32) *FdFile { + f := &FdFile{ fd: fd, name: name, flags: Flags(flags), @@ -37,10 +37,12 @@ func NewFd(fd int32, name string, flags int32) FdFile { return f } -func NewFdWithPid(fd int32, pid uint32) (f FdFile) { +func NewFdWithPid(fd int32, pid uint32) *FdFile { + f := &FdFile{ + fd: fd, + } var err error - f.fd = fd procPath := fmt.Sprintf("/proc/%d/fd/%d", pid, fd) f.name, err = os.Readlink(procPath) if err != nil { @@ -56,10 +58,10 @@ func NewFdWithPid(fd int32, pid uint32) (f FdFile) { return f } -func (f FdFile) Dup(fd int32) FdFile { - dupFd := f +func (f *FdFile) Dup(fd int32) *FdFile { + dupFd := *f dupFd.fd = fd - return dupFd + return &dupFd } func readFlagsFromFdInfo(fd int32, pid uint32) (Flags, error) { @@ -79,11 +81,11 @@ func readFlagsFromFdInfo(fd int32, pid uint32) (Flags, error) { return unknownFlag, scanner.Err() } -func (f FdFile) Name() string { +func (f *FdFile) Name() string { return f.name } -func (f FdFile) String() string { +func (f *FdFile) String() string { var sb strings.Builder if len(f.name) == 0 { @@ -100,11 +102,11 @@ func (f FdFile) String() string { return sb.String() } -func (f FdFile) Flags() Flags { +func (f *FdFile) Flags() Flags { return f.flags } -func (f FdFile) FD() int32 { +func (f *FdFile) FD() int32 { return f.fd } |
