[PATCH v2 2/6] Allow to pass pre-filled finfo data to printdev() function from upper layers

Masatake YAMATO yamato at redhat.com
Fri Mar 11 18:02:05 UTC 2022


printdev() collected struct finfo data just before printing.
If the finfo data is filled somewhere, printdev() does not
have to collect the finfo data by itself.

* src/defs.h (printfd_pid_with_finfo): New function declaration.
(printfd_pid): Inlined with using printfd_pid_with_finfo.
* src/util.c (printfd_pid_with_finfo): New function derived
from printfd_pid. printfd_pid_with_finfo takes a finfo, and passes
it to printdev.
(printdev): Add a new parameter finfo. If non-NULL finfo is given,
printdev() omits calling get_finfo_for_dev().

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 src/defs.h |  8 +++++++-
 src/util.c | 14 ++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/defs.h b/src/defs.h
index 62868fa7e..5ba088f16 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -1202,7 +1202,13 @@ extern pid_t pidfd_get_pid(pid_t pid_of_fd, int fd);
  * 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_pid_with_finfo(struct tcb *tcp, pid_t pid, int fd, struct finfo *finfo);
+
+static inline void
+printfd_pid(struct tcb *tcp, pid_t pid, int fd)
+{
+	printfd_pid_with_finfo(tcp, pid, fd, NULL);
+}
 
 static inline void
 printfd(struct tcb *tcp, int fd)
diff --git a/src/util.c b/src/util.c
index 6e61333f1..23c482527 100644
--- a/src/util.c
+++ b/src/util.c
@@ -666,10 +666,11 @@ get_finfo_for_dev(const char *path, struct finfo *finfo)
 }
 
 static bool
-printdev(struct tcb *tcp, int fd, const char *path)
+printdev(struct tcb *tcp, int fd, const char *path, struct finfo *finfo)
 {
 	struct finfo finforec;
-	struct finfo *finfo = get_finfo_for_dev(path, &finforec);
+	if (!finfo)
+		finfo = get_finfo_for_dev(path, &finforec);
 
 	switch (finfo->type) {
 	case finfo_dev_blk:
@@ -753,18 +754,19 @@ print_quoted_string_in_angle_brackets(const char *str)
 }
 
 void
-printfd_pid(struct tcb *tcp, pid_t pid, int fd)
+printfd_pid_with_finfo(struct tcb *tcp, pid_t pid, int fd, struct finfo *finfo)
 {
 	PRINT_VAL_D(fd);
 
-	char path[PATH_MAX + 1];
+	char patha[PATH_MAX + 1];
 	if (pid > 0 && !number_set_array_is_empty(decode_fd_set, 0)
-	    && getfdpath_pid(pid, fd, path, sizeof(path)) >= 0) {
+	    && (finfo || (getfdpath_pid(pid, fd, patha, sizeof(patha)) >= 0))) {
+		const char *path = finfo? finfo->path: patha;
 		if (is_number_in_set(DECODE_FD_SOCKET, decode_fd_set) &&
 		    printsocket(tcp, fd, path))
 			goto printed;
 		if (is_number_in_set(DECODE_FD_DEV, decode_fd_set) &&
-		    printdev(tcp, fd, path))
+		    printdev(tcp, fd, path, finfo))
 			goto printed;
 		if (is_number_in_set(DECODE_FD_PIDFD, decode_fd_set) &&
 		    printpidfd(pid, fd, path))
-- 
2.35.1



More information about the Strace-devel mailing list