[PATCH v3 2/6] util.c: add printfd_pid

Ákos Uzonyi uzonyi.akos at gmail.com
Sun May 24 10:41:34 UTC 2020


defs.h (printfd_pid): New function definition.
util.c (printfd_pid): New function printing the fd of an other process.
(printfd): Rewritten using printfd_pid.

Signed-off-by: Uzonyi Ákos <uzonyi.akos at gmail.com>
---
 defs.h |  6 ++++++
 util.c | 10 ++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/defs.h b/defs.h
index a7d535d7..94535a30 100644
--- a/defs.h
+++ b/defs.h
@@ -1028,6 +1028,12 @@ printpath(struct tcb *, kernel_ulong_t addr);
 
 # define TIMESPEC_TEXT_BUFSIZE \
 		(sizeof(long long) * 3 * 2 + sizeof("{tv_sec=-, tv_nsec=}"))
+
+/**
+ * Print file descriptor fd owned by process with ID pid (from the PID NS
+ * of the tracer).
+ */
+extern void printfd_pid(struct tcb *tcp, pid_t pid, int fd);
 extern void printfd(struct tcb *, int);
 /**
  * Print file descriptor fd owned by process with ID pid (from the PID NS
diff --git a/util.c b/util.c
index 0d9de2f6..9539fbb6 100644
--- a/util.c
+++ b/util.c
@@ -607,11 +607,11 @@ printpidfd(struct tcb *tcp, int fd, const char *path)
 }
 
 void
-printfd(struct tcb *tcp, int fd)
+printfd_pid(struct tcb *tcp, pid_t pid, int fd)
 {
 	char path[PATH_MAX + 1];
 	if (!number_set_array_is_empty(decode_fd_set, 0)
-	    && getfdpath(tcp, fd, path, sizeof(path)) >= 0) {
+	    && getfdpath_pid(pid, fd, path, sizeof(path)) >= 0) {
 		tprintf("%d<", (int) fd);
 		if (is_number_in_set(DECODE_FD_SOCKET, decode_fd_set) &&
 		    printsocket(tcp, fd, path))
@@ -632,6 +632,12 @@ printed:
 	}
 }
 
+void
+printfd(struct tcb *tcp, int fd)
+{
+	printfd_pid(tcp, tcp->pid, fd);
+}
+
 void
 print_pid_fd(struct tcb *tcp, pid_t pid, int fd)
 {
-- 
2.26.2



More information about the Strace-devel mailing list