[PATCH 1/7] pathtrace.c: add getfdpath_pid
Ákos Uzonyi
uzonyi.akos at gmail.com
Wed Apr 22 18:06:18 UTC 2020
* defs.h (getfdpath_pid): New function definition.
* pathtrace.c (getfdpath_pid): New function, returns the path
associated with fd of the process with pid.
(getfdpath): Rewritten using getfdpath_pid.
Signed-off-by: Uzonyi Ákos <uzonyi.akos at gmail.com>
---
defs.h | 1 +
pathtrace.c | 15 ++++++++++++---
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/defs.h b/defs.h
index 0231cbf2..a7d535d7 100644
--- a/defs.h
+++ b/defs.h
@@ -685,6 +685,7 @@ pathtrace_match(struct tcb *tcp)
return pathtrace_match_set(tcp, &global_path_set);
}
+extern int getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize);
extern int getfdpath(struct tcb *, int, char *, unsigned);
extern unsigned long getfdinode(struct tcb *, int);
extern enum sock_proto getfdproto(struct tcb *, int);
diff --git a/pathtrace.c b/pathtrace.c
index e62ff6fc..3178c447 100644
--- a/pathtrace.c
+++ b/pathtrace.c
@@ -76,10 +76,10 @@ storepath(const char *path, struct path_set *set)
}
/*
- * Get path associated with fd.
+ * Get path associated with fd of a process with pid.
*/
int
-getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
+getfdpath_pid(pid_t pid, int fd, char *buf, unsigned bufsize)
{
char linkpath[sizeof("/proc/%u/fd/%u") + 2 * sizeof(int)*3];
ssize_t n;
@@ -87,7 +87,7 @@ getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
if (fd < 0)
return -1;
- xsprintf(linkpath, "/proc/%u/fd/%u", tcp->pid, fd);
+ xsprintf(linkpath, "/proc/%u/fd/%u", pid, fd);
n = readlink(linkpath, buf, bufsize - 1);
/*
* NB: if buf is too small, readlink doesn't fail,
@@ -98,6 +98,15 @@ getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
return n;
}
+/*
+ * Get path associated with fd of tracee.
+ */
+int
+getfdpath(struct tcb *tcp, int fd, char *buf, unsigned bufsize)
+{
+ return getfdpath_pid(tcp->pid, fd, buf, bufsize);
+}
+
/*
* Add a path to the set we're tracing. Also add the canonicalized
* version of the path. Specifying NULL will delete all paths.
--
2.26.1
More information about the Strace-devel
mailing list