From: Eugene Syromyatnikov Date: Sat, 16 Sep 2017 01:02:16 +0000 (+0200) Subject: kcmp: output fds using a separate function X-Git-Tag: v4.20~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76cf3b2a98366144fa8f64651ef4161c639476b7;p=strace kcmp: output fds using a separate function This is a preparation for the future introduction of cross-NS PID derivation, which would enable us to print fd information for fds related to all processes, not just traced ones. Note the change in output type for idx1/idx2 in KCMP_FILE command from unsigned to int, it follows printfd output format. * kcmp.c (printpidfd): New function. (PRINT_FIELD_PIDFD): New macro. (SYS_FUNC(kcmp)) : Use printpidfd for printing idx1/idx2, as they are fds, after all. --- diff --git a/kcmp.c b/kcmp.c index 962952bd..e1c6e9ed 100644 --- a/kcmp.c +++ b/kcmp.c @@ -27,8 +27,25 @@ */ #include "defs.h" +#include "print_fields.h" #include "xlat/kcmp_types.h" +static void +printpidfd(struct tcb *tcp, pid_t pid, int fd) +{ + /* + * XXX We want to use printfd here, but we should figure out which + * process in strace's PID NS is referred to first. + */ + tprintf("%d", fd); +} + +#define PRINT_FIELD_PIDFD(prefix_, where_, field_, tcp_, pid_) \ + do { \ + STRACE_PRINTF("%s%s=", (prefix_), #field_); \ + printpidfd((tcp_), (pid_), (where_).field_); \ + } while (0) + SYS_FUNC(kcmp) { pid_t pid1 = tcp->u_arg[0]; @@ -42,7 +59,11 @@ SYS_FUNC(kcmp) switch (type) { case KCMP_FILE: - tprintf(", %u, %u", (unsigned) idx1, (unsigned) idx2); + tprints(", "); + printpidfd(tcp, pid1, idx1); + tprints(", "); + printpidfd(tcp, pid1, idx2); + break; case KCMP_FILES: case KCMP_FS: diff --git a/tests/kcmp.c b/tests/kcmp.c index 46bb173c..62a24d91 100644 --- a/tests/kcmp.c +++ b/tests/kcmp.c @@ -55,6 +55,12 @@ # define KCMP_SYSVSEM 6 # endif +static void +printpidfd(const char *prefix, pid_t pid, unsigned fd) +{ + printf("%s%d", prefix, fd); +} + static void do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type, const char *type_str, kernel_ulong_t idx1, kernel_ulong_t idx2) @@ -72,11 +78,13 @@ do_kcmp(kernel_ulong_t pid1, kernel_ulong_t pid2, kernel_ulong_t type, else printf("%#x /* KCMP_??? */", (int) type); - if (type == KCMP_FILE) - printf(", %u, %u", (unsigned) idx1, (unsigned) idx2); - else if (type > KCMP_SYSVSEM) + if (type == KCMP_FILE) { + printpidfd(", ", pid1, idx1); + printpidfd(", ", pid2, idx2); + } else if (type > KCMP_SYSVSEM) { printf(", %#llx, %#llx", (unsigned long long) idx1, (unsigned long long) idx2); + } printf(") = %s\n", errstr); }