From 5fa2439de2cedfaef6aca125769facd4bc3bc9b5 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 22 Mar 2025 23:27:28 +0200 Subject: SETFL --- README.md | 4 +++- cmd/ior/main.go | 4 ++++ internal/eventloop.go | 10 ++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 598e5ec..5a2abc2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# I/O Riot NG +# I/O Riot NG (aka ior) @@ -8,6 +8,8 @@ I/O Riot NG is an experiments with BPF. This program traces for I/O syscalls and Maybe this is a spiritual successor of one of my previous projects, I/O Riot https://codeberg.org/snonux/ioriot, the latter was based on SystemTap and C. The NG is based on Go, C and BPF (via libbpfgo). +This works only on Linux! + ## Fedora To get this running on Fedora 39, run: diff --git a/cmd/ior/main.go b/cmd/ior/main.go index 025abbb..2d8584a 100644 --- a/cmd/ior/main.go +++ b/cmd/ior/main.go @@ -3,8 +3,12 @@ package main import ( "ior/internal" "ior/internal/flags" + "runtime" ) func main() { + if runtime.GOOS != "linux" { + panic("Unsupported OS") + } internal.Run(flags.New()) } diff --git a/internal/eventloop.go b/internal/eventloop.go index 01ba90c..b451b69 100644 --- a/internal/eventloop.go +++ b/internal/eventloop.go @@ -249,16 +249,18 @@ func (e *eventLoop) syscallExit(exitEv event.Event, ch chan<- *event.Pair) { ev.File = file.NewFdWithPid(fd, v.Pid) } switch v.Cmd { - case syscall.F_SETFD: + case syscall.F_SETFL: fdFile, ok := ev.File.(file.FdFile) if !ok { panic("expected a file.FdFile") } - fdFile.Flags = int32(v.Arg) + fmt.Println("DEBUG BEFORE", fdFile.FlagsString()) + // fcntl(2) + canChange := syscall.O_APPEND | syscall.O_ASYNC | syscall.O_DIRECT | syscall.O_NOATIME | syscall.O_NONBLOCK + fdFile.Flags |= (int32(v.Arg) & int32(canChange)) ev.File = fdFile e.files[fd] = fdFile - case syscall.F_SETFL: - fmt.Println("TODO: F_SETFL with fcntl not yet implememented") + fmt.Println("DEBUG AFTER", fdFile.FlagsString()) case syscall.F_DUPFD: fmt.Println("TODO: F_DUPFD with fcntl not yet implememented") case syscall.F_DUPFD_CLOEXEC: -- cgit v1.2.3