aboutsummaryrefslogtreecommitdiff
path: root/tests/test_helpers/mount_unmount.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2019-01-01 22:27:40 +0100
committerJakob Unterwurzacher2019-01-01 22:27:40 +0100
commit035834dd5115cf5384e61dccfd2acc488990468f (patch)
tree1445e5faf41f0dc675e89acee35318972dfdb088 /tests/test_helpers/mount_unmount.go
parente276e255dc7d88099f35c890b704ce64117f731e (diff)
tests: ListFds: show r/w status
Also, drop entries that disappear while we stat them.
Diffstat (limited to 'tests/test_helpers/mount_unmount.go')
-rw-r--r--tests/test_helpers/mount_unmount.go27
1 files changed, 22 insertions, 5 deletions
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
}