summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-22 23:58:29 +0200
committerPaul Buetow <paul@buetow.org>2025-03-22 23:58:29 +0200
commit1612c6b346e7c1afce14b506907c83ba36ea1a84 (patch)
tree5d1be635f38d8babf1c727e71609e497b51fdf88 /internal
parentacb810dac5ae8aed48ddd4a865c7fbeca52c4e0d (diff)
catch syscall return code for fcntl success or error
Diffstat (limited to 'internal')
-rw-r--r--internal/eventloop.go16
-rw-r--r--internal/flamegraph/collapsed.go2
2 files changed, 17 insertions, 1 deletions
diff --git a/internal/eventloop.go b/internal/eventloop.go
index 102a500..60ea01a 100644
--- a/internal/eventloop.go
+++ b/internal/eventloop.go
@@ -14,9 +14,11 @@ import (
"ior/internal/file"
"ior/internal/flags"
"ior/internal/flamegraph"
+ "ior/internal/types"
. "ior/internal/types"
)
+// TOOD: read and write syscalls: can also collect amount of bytes!
type eventLoop struct {
flags flags.Flags
filter *eventFilter
@@ -230,12 +232,14 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
ev.Recycle()
return
}
+
case *NullEvent:
ev.Comm = e.comm(ev.EnterEv.GetTid())
if !e.filter.eventPair(ev) {
ev.Recycle()
return
}
+
case *FcntlEvent:
ev.Comm = e.comm(ev.EnterEv.GetTid())
fd := int32(v.Fd)
@@ -248,6 +252,16 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
ev.Recycle()
return
}
+
+ retEvent, ok := exitEv.(*types.RetEvent)
+ if !ok {
+ panic("expected *types.RetEvent")
+ }
+ // Syscall returned -1, nothing was changed with the fd
+ if retEvent.Ret == -1 {
+ break
+ }
+
switch v.Cmd {
case syscall.F_SETFL:
fdFile, ok := ev.File.(file.FdFile)
@@ -264,6 +278,7 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
case syscall.F_DUPFD_CLOEXEC:
fmt.Println("TODO: F_DUPFD_CLOEXEC with fcntl not yet implememented")
}
+
default:
panic(fmt.Sprintf("unknown type: %v", v))
}
@@ -271,6 +286,7 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) {
// TODO: implement dup syscall
// TODO: implement dup2 syscall
// TODO: implement dup3 syscall
+ // TODO: Yes, on Linux, when you use the `fork` syscall to create a subprocess, the child process shares the same file descriptors as the parent process. If the child process changes the file modes of these open file descriptors (e.g., by using `fcntl` or similar system calls), those changes will be reflected in the parent process as well, since they reference the same underlying file table entries.
ev.PrevPair, _ = e.prevPairs[ev.EnterEv.GetTid()]
ev.CalculateDurations()
diff --git a/internal/flamegraph/collapsed.go b/internal/flamegraph/collapsed.go
index 2c3e05a..de78b88 100644
--- a/internal/flamegraph/collapsed.go
+++ b/internal/flamegraph/collapsed.go
@@ -22,7 +22,7 @@ func (c *counter) merge(other counter) {
// path, traceid (syscall name), comm, pid, tid
// traceid, path is by default set in this order
// store an intermediate format which then can be converted to the others...
-// e.g. path / traceid / comm / pid / tid / counter
+// e.g. path / traceid / comm / pid / tid / flags / counter
type collapsed map[string]map[types.TraceId]counter
// TODO: Unit test this