summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2022-03-11 17:52:37 +0900
committerDmitry V. Levin <ldv@strace.io>2023-02-20 08:00:00 +0000
commitc15a5b82351bfd7e4116a8ed83f769543c5227b9 (patch)
treefd2eda0d8a3890b52669434dfaa1ff0905ee9ee3
parent940b43ed6986b3734b8e2dc1867543c120173fbf (diff)
downloadstrace-c15a5b82351bfd7e4116a8ed83f769543c5227b9.tar.gz
ioctl: collect finfo just before decoding ioctl command
This way finfo can be used as hints for decoding ioctl commands. * src/defs.h (get_finfo_for_dev): New declaration. (printfd_with_finfo): New inline function - a thin wrapper around printfd_pid_with_finfo. * src/util.c (get_finfo_for_dev): Remove static modifier to make it reusable the ioctl syscall decoder. (SYS_FUNC(ioctl)): Call get_finfo_for_dev and printfd_with_finfo instead of calling printfd. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@strace.io>
-rw-r--r--src/defs.h9
-rw-r--r--src/ioctl.c13
-rw-r--r--src/util.c2
3 files changed, 22 insertions, 2 deletions
diff --git a/src/defs.h b/src/defs.h
index 1b5f90e01..3a2bdcfae 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -671,6 +671,9 @@ struct finfo {
} dev;
};
+extern struct finfo *
+get_finfo_for_dev(const char *path, struct finfo *finfo);
+
/**
* @return 0 on success, -1 on error.
*/
@@ -1240,6 +1243,12 @@ printfd(struct tcb *tcp, int fd)
printfd_pid(tcp, tcp->pid, fd);
}
+static inline void
+printfd_with_finfo(struct tcb *tcp, int fd, const 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 ac271970e..5cb3d9df5 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -437,7 +437,18 @@ 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];
+ bool deleted;
+ if (getfdpath_pid(tcp->pid, tcp->u_arg[0], path, sizeof(path),
+ &deleted) >= 0) {
+ finfo = get_finfo_for_dev(path, &finfoa);
+ finfo->deleted = deleted;
+ printfd_with_finfo(tcp, tcp->u_arg[0], finfo);
+ } else
+ printfd(tcp, tcp->u_arg[0]);
+
tprint_arg_next();
if (xlat_verbosity != XLAT_STYLE_ABBREV)
diff --git a/src/util.c b/src/util.c
index 06609ab24..2ecb0ec19 100644
--- a/src/util.c
+++ b/src/util.c
@@ -647,7 +647,7 @@ printsocket(struct tcb *tcp, int fd, const char *path)
return true;
}
-static struct finfo *
+struct finfo *
get_finfo_for_dev(const char *path, struct finfo *finfo)
{
strace_stat_t st;