[PATCH v2 5/6] Fill finfo structure only when a decoder requests
Masatake YAMATO
yamato at redhat.com
Fri Mar 11 18:02:08 UTC 2022
This is minor optimization.
If a ioctl decoder wants to use finfo as a hint, the
decoder call tell the request to its upper layer via
newly introduced function ioctl_does_expect_finfo().
* src/ioctl.c (ioctl_does_expect_finfo): New function.
(SYS_FUNC(ioctl)): Collect finfo only when
ioctl_does_expect_finfo() returns true.
Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
src/ioctl.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/src/ioctl.c b/src/ioctl.c
index a839da817..d675c9763 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -429,6 +429,20 @@ ioctl_decode(struct tcb *tcp)
return 0;
}
+/*
+ * If your ioctl decoder needs the extra inforamtion
+ * about a fd for later processing, return true.
+ */
+static bool ioctl_does_expect_finfo(struct tcb *tcp)
+{
+ const unsigned int code = tcp->u_arg[1];
+ switch (_IOC_TYPE(code)) {
+ case 'T':
+ return true;
+ }
+ return false;
+}
+
SYS_FUNC(ioctl)
{
const struct_ioctlent *iop;
@@ -438,7 +452,8 @@ SYS_FUNC(ioctl)
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)
+ if (ioctl_does_expect_finfo(tcp)
+ && 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();
--
2.35.1
More information about the Strace-devel
mailing list