[PATCH v2 3/6] Collect finfo just before decoding ioctl command

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


In preparation of using the finfo elsewhere.

* src/defs.h (get_finfo_for_dev): New declaration.
(printfd_with_finfo): New inline function extending
printfd_pid_with_finfo.
* src/util.c (get_finfo_for_dev): Remove static modifier to
make it reusable at the ioctl decoder.
(SYS_FUNC(ioctl)): Call get_finfo_for_dev and printfd_with_finfo
instead of calling printfd.

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

diff --git a/src/defs.h b/src/defs.h
index 5ba088f16..8cfc8d767 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -665,6 +665,9 @@ struct finfo {
 	} dev;
 };
 
+extern
+struct finfo *get_finfo_for_dev(const char *path, struct finfo *finfo);
+
 /**
  * @return 0 on success, -1 on error.
  */
@@ -1216,6 +1219,12 @@ printfd(struct tcb *tcp, int fd)
 	printfd_pid(tcp, tcp->pid, fd);
 }
 
+static inline void
+printfd_with_finfo(struct tcb *tcp, int fd, struct finfo *finfo)
+{
+	printfd_pid_with_finfo(tcp, tcp->pid, fd, finfo);
+}
+
 /**
  * Helper function, converts pid to string, or to "self" for pid == 0.
  * Uses static buffer for operation.
diff --git a/src/ioctl.c b/src/ioctl.c
index 8173bdc6b..0f9f0c9a9 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -432,7 +432,12 @@ SYS_FUNC(ioctl)
 	int ret;
 
 	if (entering(tcp)) {
-		printfd(tcp, tcp->u_arg[0]);
+		struct finfo finfoa;
+		struct finfo *finfo = NULL;
+		char path[PATH_MAX + 1];
+		if (getfdpath_pid(tcp->pid, tcp->u_arg[0], path, sizeof(path)) >= 0)
+			finfo = get_finfo_for_dev(path, &finfoa);
+		printfd_with_finfo(tcp, tcp->u_arg[0], finfo);
 		tprint_arg_next();
 
 		if (xlat_verbosity != XLAT_STYLE_ABBREV)
diff --git a/src/util.c b/src/util.c
index 23c482527..55a87bb05 100644
--- a/src/util.c
+++ b/src/util.c
@@ -631,7 +631,7 @@ printsocket(struct tcb *tcp, int fd, const char *path)
 	return false;
 }
 
-static struct finfo *
+struct finfo *
 get_finfo_for_dev(const char *path, struct finfo *finfo)
 {
 	strace_stat_t st;
-- 
2.35.1



More information about the Strace-devel mailing list