diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-11 07:18:43 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-11 07:31:58 +0900 |
| commit | 9dec9dbc4bbd09a59cf35f4000d26794b42edcfc (patch) | |
| tree | 760bbf0d62666b590a6ee45324685adac358de32 /test/sandbox/tool | |
| parent | 2f74adc8bdeda2499be0a8b2711f68c342695bf2 (diff) | |
container/init: close setup pipe early
This prevents leaking the setup pipe.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'test/sandbox/tool')
| -rw-r--r-- | test/sandbox/tool/main.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/sandbox/tool/main.go b/test/sandbox/tool/main.go index cd7322e3..ef3325de 100644 --- a/test/sandbox/tool/main.go +++ b/test/sandbox/tool/main.go @@ -67,6 +67,39 @@ func main() { case "hash": // this eases the pain of passing the hash to python fmt.Print(flagBpfHash) + case "fd": + if len(args) != 2 { + log.Fatal("invalid argument") + } + prefix := fmt.Sprintf("/proc/%s/fd/", args[1]) + + var fail bool + if entries, err := os.ReadDir(prefix); err != nil { + log.Fatal(err.Error()) + } else { + for _, ent := range entries { + var fd int + if fd, err = strconv.Atoi(ent.Name()); err != nil { + log.Fatal(err.Error()) + } + + // skip standard streams + if fd <= 2 { + continue + } + fail = true + + var d string + if d, err = os.Readlink(prefix + ent.Name()); err != nil { + log.Fatal(err.Error()) + } + log.Printf("[FAIL] extra fd %d -> %s", fd, d) + } + } + if fail { + log.Fatal("[FAIL] file descriptors leaked") + } + default: log.Fatal("invalid argument") } |
