summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2022-03-11 17:13:41 +0900
committerDmitry V. Levin <ldv@strace.io>2023-02-19 08:00:00 +0000
commit940b43ed6986b3734b8e2dc1867543c120173fbf (patch)
treebfa23d390b454c5d0a0133c7ddbeafe9a6ba5339
parent0958b5fcd336ca7b5a8da957df0fcb7f8526ff17 (diff)
downloadstrace-940b43ed6986b3734b8e2dc1867543c120173fbf.tar.gz
Allow to pass pre-filled finfo data to printdev() from upper layers
printdev() used to collect struct finfo data just before printing. However, if the finfo data can be filled somewhere else, printdev() does not have to collect the finfo data by itself. * src/defs.h (printfd_pid_with_finfo): New function declaration. (printfd_pid): Turn into a thin wrapper around printfd_pid_with_finfo. (struct finfo): New member "deleted". * src/util.c (get_finfo_for_dev): Initialize "deleted" member of finfo. (printdev): Add finfo argument. If non-NULL is specified as finfo argument, omit get_finfo_for_dev invocation. (printfd_pid): Rename to printfd_pid_with_finfo, add finfo argument and pass it on to printdev. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Signed-off-by: Dmitry V. Levin <ldv@strace.io>
-rw-r--r--src/defs.h10
-rw-r--r--src/util.c18
2 files changed, 20 insertions, 8 deletions
diff --git a/src/defs.h b/src/defs.h
index eb8675757..1b5f90e01 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -665,6 +665,7 @@ struct finfo {
FINFO_DEV_BLK,
FINFO_DEV_CHR,
} type;
+ bool deleted;
struct {
unsigned int major, minor;
} dev;
@@ -1224,7 +1225,14 @@ 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,
+ const 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 1d140fa91..06609ab24 100644
--- a/src/util.c
+++ b/src/util.c
@@ -654,6 +654,7 @@ get_finfo_for_dev(const char *path, struct finfo *finfo)
finfo->path = path;
finfo->type = FINFO_UNSET;
+ finfo->deleted = false;
if (path[0] != '/')
return finfo;
@@ -681,10 +682,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, const struct finfo *finfo)
{
struct finfo finfo_buf;
- const struct finfo *finfo = get_finfo_for_dev(path, &finfo_buf);
+ if (!finfo)
+ finfo = get_finfo_for_dev(path, &finfo_buf);
switch (finfo->type) {
case FINFO_DEV_BLK:
@@ -779,25 +781,27 @@ print_quoted_string_in_angle_brackets(const char *str, const bool deleted)
}
void
-printfd_pid(struct tcb *tcp, pid_t pid, int fd)
+printfd_pid_with_finfo(struct tcb *tcp, pid_t pid, int fd, const struct finfo *finfo)
{
PRINT_VAL_D(fd);
- char path[PATH_MAX + 1];
+ char patha[PATH_MAX + 1];
bool deleted;
if (pid > 0 && !number_set_array_is_empty(decode_fd_set, 0)
- && getfdpath_pid(pid, fd, path, sizeof(path), &deleted) >= 0) {
+ && (finfo || (getfdpath_pid(pid, fd, patha, sizeof(patha), &deleted) >= 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))
goto printed;
if (is_number_in_set(DECODE_FD_PATH, decode_fd_set))
- print_quoted_string_in_angle_brackets(path, deleted);
+ print_quoted_string_in_angle_brackets(path,
+ finfo? finfo->deleted: deleted);
printed: ;
}