[strace/strace] Print cwd path to AT_FDCWD when -y (--decode-fd=path) flag is used (#194)

Renaud Métrich notifications at github.com
Mon Sep 20 10:12:37 UTC 2021


When syscalls use *AT_FDCWD* (e.g. `openat()`), it's not always obvious to determine the current directory, one need to search back for any `chdir()` syscall, in the process or some parent.

This patch prints the path when `-y` (`--decode-fd=path`) flag is used, e.g.:
~~~
openat(AT_FDCWD</home/rmetrich/GIT/strace>, "/lib64/libselinux.so.1" ...)
~~~

Note the initial commit only printed when `-y` was specified, but it appears that apparently the path decoding for FDs is always performed, even when `--decode-fd=dev` only is specified for example, hence the final code proposes to keep this behaviour:
as soon as `--decode-fd` is used, *AT_FDCWD* gets decoded.

Because decoding makes use of `realpath()` which is known to be slow, the decoded path is cached.

This explains the many commits, all this can be merged if necessary later.
You can view, comment on, or merge this pull request online at:

  https://github.com/strace/strace/pull/194

-- Commit Summary --

  * Print cwd path to AT_FDCWD when -y (--decode-fd=path) flag is used
  * Implement a cache for current working directory
  * Print path for AT_FDCWD whenever decode_fd is used
  * tests: adjusted tests for AT_FDCWD decoding

-- File Changes --

    M src/chdir.c (16)
    M src/defs.h (2)
    M src/open.c (22)
    M src/strace.c (5)
    M src/syscall_dummy.h (16)
    M src/umount.c (7)
    M tests/dev-yy.c (5)
    M tests/faccessat.c (21)
    M tests/faccessat2.c (4)
    M tests/fsconfig.c (10)
    M tests/fspick.c (7)
    M tests/mount_setattr.c (7)
    M tests/move_mount.c (29)
    M tests/open_tree.c (7)
    M tests/openat2.c (22)

-- Patch Links --

https://github.com/strace/strace/pull/194.patch
https://github.com/strace/strace/pull/194.diff

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/strace/strace/pull/194
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20210920/cbf9c9a4/attachment.htm>


More information about the Strace-devel mailing list