]> granicus.if.org Git - strace/commitdiff
kcmp: output fds using a separate function
authorEugene Syromyatnikov <evgsyr@gmail.com>
Sat, 16 Sep 2017 01:02:16 +0000 (03:02 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 17 Sep 2017 12:04:11 +0000 (12:04 +0000)
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)) <case KCMP_FILE>: Use printpidfd for printing
idx1/idx2, as they are fds, after all.

kcmp.c
tests/kcmp.c

diff --git a/kcmp.c b/kcmp.c
index 962952bd957fd7864a92f00b51a6e236f35ec6a0..e1c6e9ed0532bd299c201f0a3b2ff99011a46d96 100644 (file)
--- a/kcmp.c
+++ b/kcmp.c
  */
 
 #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:
index 46bb173c55b5c3ff061f97853866aae98ff130eb..62a24d91517aed0d8aa0eaedaecd1d3e3cb5fe7f 100644 (file)
 #  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);
 }