diff options
author | Ákos Uzonyi <uzonyi.akos@gmail.com> | 2020-06-30 17:20:12 +0200 |
---|---|---|
committer | Dmitry V. Levin <ldv@altlinux.org> | 2020-08-25 14:29:30 +0000 |
commit | 18c2208b05f5b7bcca5b000d601a1e332a63c850 (patch) | |
tree | 0b8ab61a3b909025f800dca7d0ec6a3a6ef17127 | |
parent | 173257d9987cd525eb6a96492f4ead125aa316f4 (diff) | |
download | strace-18c2208b05f5b7bcca5b000d601a1e332a63c850.tar.gz |
Use get_proc_pid for /proc paths
* mmap_cache.c (mmap_cache_rebuild_if_invalid): Use proc pid instead of
tcp->pid for /proc path.
* util.c (getfdproto): Likewise.
(pidfd_get_pid): Likewise.
* pathtrace.c (getfdpath_pid): Likewise.
* strace.c (attach_tcb): Likewise.
-rw-r--r-- | mmap_cache.c | 2 | ||||
-rw-r--r-- | pathtrace.c | 7 | ||||
-rw-r--r-- | strace.c | 2 | ||||
-rw-r--r-- | util.c | 9 |
4 files changed, 15 insertions, 5 deletions
diff --git a/mmap_cache.c b/mmap_cache.c index 89c622549..9825df269 100644 --- a/mmap_cache.c +++ b/mmap_cache.c @@ -84,7 +84,7 @@ mmap_cache_rebuild_if_invalid(struct tcb *tcp, const char *caller) return MMAP_CACHE_REBUILD_READY; char filename[sizeof("/proc/4294967296/maps")]; - xsprintf(filename, "/proc/%u/maps", tcp->pid); + xsprintf(filename, "/proc/%u/maps", get_proc_pid(tcp)); FILE *fp = fopen_stream(filename, "r"); if (!fp) { diff --git a/pathtrace.c b/pathtrace.c index 5b60762bc..afed770a3 100644 --- a/pathtrace.c +++ b/pathtrace.c @@ -87,7 +87,12 @@ getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize) if (fd < 0) return -1; - xsprintf(linkpath, "/proc/%u/fd/%u", pid, fd); + int proc_pid = 0; + translate_pid(NULL, pid, PT_TID, &proc_pid); + if (!proc_pid) + return -1; + + xsprintf(linkpath, "/proc/%u/fd/%u", proc_pid, fd); n = readlink(linkpath, buf, bufsize - 1); /* * NB: if buf is too small, readlink doesn't fail, @@ -1202,7 +1202,7 @@ attach_tcb(struct tcb *const tcp) unsigned int ntid = 0, nerr = 0; if (followfork && tcp->pid != strace_child && - xsprintf(procdir, task_path, tcp->pid) > 0 && + xsprintf(procdir, task_path, get_proc_pid(tcp)) > 0 && (dir = opendir(procdir)) != NULL) { struct_dirent *de; @@ -501,7 +501,7 @@ getfdproto(struct tcb *tcp, int fd) if (fd < 0) return SOCK_PROTO_UNKNOWN; - xsprintf(path, "/proc/%u/fd/%u", tcp->pid, fd); + xsprintf(path, "/proc/%u/fd/%u", get_proc_pid(tcp), fd); r = getxattr(path, "system.sockprotoname", buf, bufsize - 1); if (r <= 0) return SOCK_PROTO_UNKNOWN; @@ -582,8 +582,13 @@ printdev(struct tcb *tcp, int fd, const char *path) pid_t pidfd_get_pid(pid_t pid_of_fd, int fd) { + int proc_pid = 0; + translate_pid(NULL, pid_of_fd, PT_TID, &proc_pid); + if (!proc_pid) + return -1; + char fdi_path[sizeof("/proc/%u/fdinfo/%u") + 2 * sizeof(int) * 3]; - xsprintf(fdi_path, "/proc/%u/fdinfo/%u", pid_of_fd, fd); + xsprintf(fdi_path, "/proc/%u/fdinfo/%u", proc_pid, fd); FILE *f = fopen_stream(fdi_path, "r"); if (!f) |