[PATCH 6/9] aio: Use printfd for fd printing

Eugene Syromyatnikov evgsyr at gmail.com
Mon Sep 5 01:32:16 UTC 2016


struct iocb contains two fields with fd semantics: aio_fildes and
aio_resfd. It is quite reasonable to use appropriate function for
printing them (apart from just "%d").

* aio.c (print_common_flags): Add struct tcb pointer to parameter list;
  use printfd for printing aio_resfd field.
  (print_iocb_header): Add struct tcb pointer to parameter list; use
  printfd for printing aio_fildes field.
  (print_iocb): provide tcp argument to print_iocb_header and
  print_common_flags.
  (SYS_FUNC(io_cancel)): Likewise.
---
 aio.c |   21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/aio.c b/aio.c
index 29562d2..7b908d4 100644
--- a/aio.c
+++ b/aio.c
@@ -78,12 +78,14 @@ tprint_lio_opcode(unsigned cmd)
 }
 
 static void
-print_common_flags(const struct iocb *cb)
+print_common_flags(struct tcb *tcp, const struct iocb *cb)
 {
 /* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
 #ifdef IOCB_FLAG_RESFD
-	if (cb->aio_flags & IOCB_FLAG_RESFD)
-		tprintf(", resfd=%d", cb->aio_resfd);
+	if (cb->aio_flags & IOCB_FLAG_RESFD) {
+		tprints(", resfd=");
+		printfd(tcp, cb->aio_resfd);
+	}
 	if (cb->aio_flags & ~IOCB_FLAG_RESFD)
 		tprintf(", flags=%x", cb->aio_flags);
 #endif
@@ -98,7 +100,7 @@ iocb_is_valid(const struct iocb *cb)
 }
 
 static enum iocb_sub
-print_iocb_header(const struct iocb *cb)
+print_iocb_header(struct tcb *tcp, const struct iocb *cb)
 {
 	enum iocb_sub sub;
 
@@ -113,7 +115,8 @@ print_iocb_header(const struct iocb *cb)
 	if (cb->aio_reqprio)
 		tprintf(", reqprio=%hd", cb->aio_reqprio);
 
-	tprintf(", fildes=%d", cb->aio_fildes);
+	tprints(", fildes=");
+	printfd(tcp, cb->aio_fildes);
 
 	return sub;
 }
@@ -121,7 +124,7 @@ print_iocb_header(const struct iocb *cb)
 static void
 print_iocb(struct tcb *tcp, const struct iocb *cb)
 {
-	enum iocb_sub sub = print_iocb_header(cb);
+	enum iocb_sub sub = print_iocb_header(tcp, cb);
 
 	switch (sub) {
 	case SUB_COMMON:
@@ -134,7 +137,7 @@ print_iocb(struct tcb *tcp, const struct iocb *cb)
 		}
 		tprintf(", nbytes=%" PRIu64 ", offset=%" PRId64,
 			(uint64_t) cb->aio_nbytes, (int64_t) cb->aio_offset);
-		print_common_flags(cb);
+		print_common_flags(tcp, cb);
 		break;
 	case SUB_VECTOR:
 		if (iocb_is_valid(cb)) {
@@ -149,7 +152,7 @@ print_iocb(struct tcb *tcp, const struct iocb *cb)
 				(uint64_t) cb->aio_nbytes);
 		}
 		tprintf(", offset=%" PRId64, (int64_t) cb->aio_offset);
-		print_common_flags(cb);
+		print_common_flags(tcp, cb);
 		break;
 	case SUB_NONE:
 		break;
@@ -214,7 +217,7 @@ SYS_FUNC(io_cancel)
 
 		if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
 			tprints("{");
-			print_iocb_header(&cb);
+			print_iocb_header(tcp, &cb);
 			tprints("}");
 		}
 		tprints(", ");
-- 
1.7.10.4





More information about the Strace-devel mailing list