summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-21 12:28:12 +0200
committerPaul Buetow <paul@buetow.org>2026-02-21 12:28:12 +0200
commit480162734c196b4b966a7f5a1c5df3749cd129c6 (patch)
tree31406644a6625a5d38d309d9219682c65e22fbb3
parent776910425e216bd2db9fbd78bfea8508ba7076c4 (diff)
Handle unknown flags for openat2
Amp-Thread-ID: https://ampcode.com/threads/T-019c7faf-baaa-704f-af15-8aeba9df4628 Co-authored-by: Amp <amp@ampcode.com>
-rw-r--r--FIXES.md5
-rw-r--r--internal/file/file.go18
-rw-r--r--internal/file/file_test.go17
3 files changed, 26 insertions, 14 deletions
diff --git a/FIXES.md b/FIXES.md
new file mode 100644
index 0000000..0bd8700
--- /dev/null
+++ b/FIXES.md
@@ -0,0 +1,5 @@
+## Plan
+1. Prevent `openat2` file tracking from panicking on unknown flags by allowing `-1` (unknown) flags in userland and covering it with a focused test.
+2. Decide whether to enable `name_to_handle_at`/`open_by_handle_at` tracing or remove the correlation logic if the tracepoints stay excluded.
+3. Add `close_range` handling that removes all fds in the range from the fd table.
+4. Improve `io_uring_*` attribution by correlating setup/enter operations with returned fds or otherwise marking them as non-file-backed operations.
diff --git a/internal/file/file.go b/internal/file/file.go
index 85894c9..ff8dae2 100644
--- a/internal/file/file.go
+++ b/internal/file/file.go
@@ -24,15 +24,15 @@ type FdFile struct {
}
func NewFd(fd int32, name string, flags int32) FdFile {
- f := FdFile{
- fd: fd,
- name: name,
- flags: Flags(flags),
- }
- if f.flags == -1 {
- panic(fmt.Sprintf("DEBUG with -1 flags: %v", f))
- }
- return f
+ f := FdFile{
+ fd: fd,
+ name: name,
+ flags: Flags(flags),
+ }
+ if f.flags == -1 {
+ f.flags = unknownFlag
+ }
+ return f
}
func NewFdWithPid(fd int32, pid uint32) (f FdFile) {
diff --git a/internal/file/file_test.go b/internal/file/file_test.go
index 22610ea..726de5a 100644
--- a/internal/file/file_test.go
+++ b/internal/file/file_test.go
@@ -6,10 +6,17 @@ import (
)
func TestStringValue(t *testing.T) {
- var array [128]byte
- copy(array[:], "test string")
+ var array [128]byte
+ copy(array[:], "test string")
- if str := types.StringValue(array[:]); str != "test string" {
- t.Errorf("epxected 'test string' but got '%s' with bytes '%v'", str, []byte(str))
- }
+ if str := types.StringValue(array[:]); str != "test string" {
+ t.Errorf("epxected 'test string' but got '%s' with bytes '%v'", str, []byte(str))
+ }
+}
+
+func TestNewFdUnknownFlags(t *testing.T) {
+ fdFile := NewFd(1, "test.txt", -1)
+ if fdFile.Flags() != unknownFlag {
+ t.Errorf("expected unknown flags, got %v", fdFile.Flags())
+ }
}