From 035834dd5115cf5384e61dccfd2acc488990468f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 1 Jan 2019 22:27:40 +0100 Subject: tests: ListFds: show r/w status Also, drop entries that disappear while we stat them. --- tests/test_helpers/mount_unmount.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'tests/test_helpers') diff --git a/tests/test_helpers/mount_unmount.go b/tests/test_helpers/mount_unmount.go index 5035c2b..e2eaf1f 100644 --- a/tests/test_helpers/mount_unmount.go +++ b/tests/test_helpers/mount_unmount.go @@ -176,14 +176,31 @@ func ListFds(pid int) []string { log.Panic(err) } defer f.Close() + // Note: Readdirnames filters "." and ".." names, err := f.Readdirnames(0) if err != nil { log.Panic(err) } - for i, n := range names { - // Note: Readdirnames filters "." and ".." - target, _ := os.Readlink(dir + "/" + n) - names[i] = n + "=" + target + var out []string + for _, n := range names { + fdPath := dir + "/" + n + fi, err := os.Lstat(fdPath) + if err != nil { + // fd was closed in the meantime + continue + } + if fi.Mode()&0400 > 0 { + n += "r" + } + if fi.Mode()&0200 > 0 { + n += "w" + } + target, err := os.Readlink(fdPath) + if err != nil { + // fd was closed in the meantime + continue + } + out = append(out, n+"="+target) } - return names + return out } -- cgit v1.2.3