[RFC PATCH 14/15] kcmp.c: fix path decoding

Ákos Uzonyi uzonyi.akos at gmail.com
Mon Jun 1 11:44:43 UTC 2020


* kcmp.c SYS_FUNC(kcmp): Fix some pid arguments.
* tests/kcmp.c (printpidfd): Print path if VERBOSE_FD
(main): Use our real pid if real fds are used.
---
 kcmp.c       |  6 +++---
 tests/kcmp.c | 21 +++++++++++++++++++--
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/kcmp.c b/kcmp.c
index 6819265b..ef46455c 100644
--- a/kcmp.c
+++ b/kcmp.c
@@ -38,7 +38,7 @@ SYS_FUNC(kcmp)
 			tprints(", ");
 			printfd_pid_tracee_ns(tcp, pid1, idx1);
 			tprints(", ");
-			printfd_pid_tracee_ns(tcp, pid1, idx2);
+			printfd_pid_tracee_ns(tcp, pid2, idx2);
 
 			break;
 
@@ -52,8 +52,8 @@ SYS_FUNC(kcmp)
 			if (umove_or_printaddr(tcp, idx2, &slot))
 				break;
 
-			PRINT_FIELD_PIDFD("{",  slot, efd, tcp, pid2);
-			PRINT_FIELD_PIDFD(", ", slot, tfd, tcp, pid2);
+			PRINT_FIELD_PIDFD("{",  slot, efd, tcp, pid1);
+			PRINT_FIELD_PIDFD(", ", slot, tfd, tcp, pid1);
 			PRINT_FIELD_U(", ", slot, toff);
 			tprints("}");
 
diff --git a/tests/kcmp.c b/tests/kcmp.c
index a46da0ed..b0b276f5 100644
--- a/tests/kcmp.c
+++ b/tests/kcmp.c
@@ -64,7 +64,24 @@ static const char zero_path[] = "/dev/zero";
 static void
 printpidfd(const char *prefix, pid_t pid, unsigned fd)
 {
-	printf("%s%d", prefix, fd);
+	const char *path = NULL;
+
+# if VERBOSE_FD
+	switch (fd)
+	{
+	case NULL_FD:
+		path = null_path;
+		break;
+	case ZERO_FD:
+		path = zero_path;
+		break;
+	}
+# endif
+
+	if (path)
+		printf("%s%d<%s>", prefix, fd, path);
+	else
+		printf("%s%d", prefix, fd);
 }
 
 /*
@@ -179,7 +196,7 @@ main(void)
 	/* KCMP_FILE is the only type which has additional args */
 	do_kcmp(3141592653U, 2718281828U, ARG_STR(KCMP_FILE), bogus_idx1,
 		bogus_idx2);
-	do_kcmp(-1, -1, ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
+	do_kcmp(getpid(), getpid(), ARG_STR(KCMP_FILE), NULL_FD, ZERO_FD);
 
 	/* Types without additional args */
 	do_kcmp(-1, -1, ARG_STR(KCMP_VM), bogus_idx1, bogus_idx2);
-- 
2.26.2



More information about the Strace-devel mailing list