[PATCH 4/4] Use printpid for printing pid of pidfd
Ákos Uzonyi
uzonyi.akos at gmail.com
Sat Sep 4 17:55:58 UTC 2021
On Fri, 3 Sept 2021 at 22:29, Masatake YAMATO <yamato at redhat.com> wrote:
>
> * src/util.c (printpidfd): Use printfd instead of
> PRINT_VAL_D.
>
> * src/pidns.c (printfd): Allow to pass NULL
> as tcb when PID translation is not needed.
>
> Suggested-by: Ákos Uzonyi <uzonyi.akos at gmail.com>
> Signed-off-by: Masatake YAMATO <yamato at redhat.com>
> ---
> src/pidns.c | 3 ++-
> src/util.c | 4 +++-
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/src/pidns.c b/src/pidns.c
> index 9c7b7ce1a..59703d8c4 100644
> --- a/src/pidns.c
> +++ b/src/pidns.c
> @@ -539,7 +539,8 @@ void
> printpid(struct tcb *tcp, int pid, enum pid_type type)
> {
> PRINT_VAL_D(pid);
> - printpid_translation(tcp, pid, type);
> + if (tcp)
> + printpid_translation(tcp, pid, type);
> }
The null tcp parameter is already handled in translate_pid, so this
change is not needed (the pid will be "translated" to itself, so
printpid_tranlsation won't actually print anything). For now it
doesn't change the behavior, but after adding comm field printing (in
case you plan to follow my idea, to do the comm field printing in
printpid_translation (which should be renamed then to
printpid_decoding for example)), this "if" would be problematic, as
comm fields wouldn't get printed when tcp is null.
> void
> diff --git a/src/util.c b/src/util.c
> index c944b3816..f9017b165 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -641,7 +641,9 @@ printpidfd(pid_t pid_of_fd, int fd, const char *path)
> return false;
>
> tprints("pid:");
> - PRINT_VAL_D(pid);
> + /* The pid translation is not needed because
> + * the pid is in strace's namespace. */
> + printpid(NULL, pid, PT_TID);
> return true;
>
More information about the Strace-devel
mailing list