[PATCH v2 4/6] util.c: add pidfd_get_pid
Dmitry V. Levin
ldv at altlinux.org
Sat May 23 21:56:15 UTC 2020
On Fri, May 15, 2020 at 09:18:38PM +0200, Ákos Uzonyi wrote:
> * defs.h (pidfd_get_pid): New function definition.
> * utils.c (pidfd_get_pid): New function, returns the pid of a pidfd.
> (printpidfd): Rewritten using pidfd_get_pid.
> (printfd_pid): Changed printpidfd arguments
>
> Signed-off-by: Ákos Uzonyi <uzonyi.akos at gmail.com>
> ---
> defs.h | 4 ++++
> util.c | 37 +++++++++++++++++++------------------
> 2 files changed, 23 insertions(+), 18 deletions(-)
>
> diff --git a/defs.h b/defs.h
> index 39985bbe..c0bda6ce 100644
> --- a/defs.h
> +++ b/defs.h
> @@ -1029,6 +1029,10 @@ printpath(struct tcb *, kernel_ulong_t addr);
> # define TIMESPEC_TEXT_BUFSIZE \
> (sizeof(long long) * 3 * 2 + sizeof("{tv_sec=-, tv_nsec=}"))
>
> +/**
> + * Returns the pid associated with pidfd of the process with ID pid_of_fd
> + */
> +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).
> diff --git a/util.c b/util.c
> index 3f562efc..4d3f77fb 100644
> --- a/util.c
> +++ b/util.c
> @@ -567,43 +567,44 @@ printdev(struct tcb *tcp, int fd, const char *path)
> return false;
> }
>
> -static bool
> -printpidfd(struct tcb *tcp, int fd, const char *path)
> +pid_t
> +pidfd_get_pid(pid_t pid_of_fd, int fd)
> {
> - static const char pidfd_path[] = "anon_inode:[pidfd]";
> -
> - if (strcmp(path, pidfd_path))
> - return false;
> -
Please keep this optimization in printpidfd,
it may save quite a few syscalls when fd is not a pidfd.
--
ldv
More information about the Strace-devel
mailing list