summaryrefslogtreecommitdiff
path: root/internal/file/file.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-03-24 21:37:54 +0200
committerPaul Buetow <paul@buetow.org>2025-03-24 21:37:54 +0200
commit26be49ea3cc2516ab7d26b629e7edc93a296596d (patch)
tree49f6d8730a937375a755291037b3d388abb1f0cf /internal/file/file.go
parent6834a4c4094d133e771491b134e8da73a9f00a07 (diff)
parenta78769805d408308a1d85f9b2fb45a1af3450f13 (diff)
add fork testMerge branch 'main' of codeberg.org:snonux/ior
Diffstat (limited to 'internal/file/file.go')
-rw-r--r--internal/file/file.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/internal/file/file.go b/internal/file/file.go
index 513212b..71b8a09 100644
--- a/internal/file/file.go
+++ b/internal/file/file.go
@@ -18,7 +18,7 @@ type File interface {
type FdFile struct {
fd int32
name string
- Flags int32
+ Flags *int32 // TODO: This must be a pointer as via dup(2) - means, we need to synchronise access as well .. use atomicint
flagsFromFdInfo bool
}
@@ -26,17 +26,19 @@ func NewFd(fd int32, name []byte, flags int32) FdFile {
return FdFile{
fd: fd,
name: stringValue(name),
- Flags: flags,
+ Flags: &flags,
}
}
func NewFdWithPid(fd int32, pid uint32) FdFile {
linkName, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%d", pid, fd))
if err != nil {
+ fmt.Println("DEBUG", err)
+ var unknownFlags int32 = -1
return FdFile{
fd: fd,
name: "?",
- Flags: -1,
+ Flags: &unknownFlags, // Unknown flags at this point
flagsFromFdInfo: true,
}
}
@@ -45,11 +47,18 @@ func NewFdWithPid(fd int32, pid uint32) FdFile {
return FdFile{
fd: fd,
name: linkName,
- Flags: flags,
+ Flags: &flags,
flagsFromFdInfo: true,
}
}
+func (f FdFile) Dup(fd int32) FdFile {
+ duppedFd := f
+ duppedFd.fd = fd
+ duppedFd.flagsFromFdInfo = false
+ return duppedFd
+}
+
func readFlagsFromFdInfo(fd int32, pid uint32) (int32, error) {
data, err := os.ReadFile(fmt.Sprintf("/proc/%d/fdinfo/%d", pid, fd))
if err != nil {
@@ -72,7 +81,11 @@ func (f FdFile) Name() string {
}
func (f FdFile) FlagsString() string {
- return flagsToStr(f.Flags)
+ var flags int32 = -1
+ if f.Flags != nil {
+ flags = *f.Flags
+ }
+ return flagsToStr(flags)
}
func (f FdFile) String() string {