[PATCH v4 01/10] kcmp.c: fix path decoding

Ákos Uzonyi uzonyi.akos at gmail.com
Sat Jun 13 16:18:28 UTC 2020


* kcmp.c (SYS_FUNC(kcmp)): Fix KCMP_FILE pid arguments.
* tests/kcmp.c (printpidfd): Print path if VERBOSE_FD.
(main): Use our real pid if real fds are used.
---
 kcmp.c       |  2 +-
 tests/kcmp.c | 25 ++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/kcmp.c b/kcmp.c
index 6819265b..62115555 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;
 
diff --git a/tests/kcmp.c b/tests/kcmp.c
index a46da0ed..dc5ba9a4 100644
--- a/tests/kcmp.c
+++ b/tests/kcmp.c
@@ -64,7 +64,26 @@ 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
+	if (pid == getpid()) {
+		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 +198,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);
@@ -198,7 +217,7 @@ main(void)
 	for (i = 0; i < ARRAY_SIZE(slot_data); i++) {
 		memcpy(slot, slot_data + i, sizeof(*slot));
 
-		do_kcmp(getpid(), getppid(), ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
+		do_kcmp(getpid(), -1, ARG_STR(KCMP_EPOLL_TFD), NULL_FD,
 			(uintptr_t) slot, 1);
 	}
 
-- 
2.27.0



More information about the Strace-devel mailing list