[PATCH 2/4] Use the definition of struct mmsghdr if it is defined in build environment

Masatake YAMATO yamato at redhat.com
Thu Nov 6 16:23:25 UTC 2014


mmsghrd structure type is defined locally in printmmsghdr function.

However, more functions will refer the definition in modifications for
supporting "-e write=all" and "-e read=all" option for sendmmsg and
recvmmsg system calls.

In this patch, strace uses the definition of struct mmsghdr in build
environment if configure reports it is available; and uses own
definition in the top level of net.c if configure doesn't reports it
is available.

* configure.ac (struct mmsghdr): Check whether the structure
  definition is available or not.

* net.c (struct mmsghdr): Define the structure type if configure
  doesn't report it is available in the build environment.

  (printmmsghdr): Don't define struct mmsghdr type locally.

Signed-off-by: Masatake YAMATO <yamato at redhat.com>
---
 configure.ac |  4 ++++
 net.c        | 12 ++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 9caa835..01df6f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -260,6 +260,10 @@ AC_CHECK_TYPES([struct sigcontext],,, [#include <signal.h>])
 AC_CHECK_HEADERS([netinet/tcp.h netinet/udp.h],,, [#include <netinet/in.h>])
 
 AC_CHECK_MEMBERS([struct msghdr.msg_control],,, [#include <sys/socket.h>])
+AC_CHECK_TYPES([struct mmsghdr],,, [
+#define _GNU_SOURCE
+#include <sys/socket.h>
+])
 
 AC_CHECK_TYPES([struct __old_kernel_stat],,, [#include <asm/stat.h>])
 
diff --git a/net.c b/net.c
index 193705d..53c2a02 100644
--- a/net.c
+++ b/net.c
@@ -392,6 +392,13 @@ struct mmsghdr32 {
 	uint32_t /* unsigned */ msg_len;
 };
 
+#ifndef HAVE_STRUCT_MMSGHDR
+struct mmsghdr {
+	struct msghdr msg_hdr;
+	unsigned msg_len;
+};
+#endif
+
 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
 static void
 copy_from_msghdr32(struct msghdr *to_msg, struct msghdr32 *from_msg32)
@@ -446,10 +453,7 @@ dumpiov_in_msghdr(struct tcb *tcp, long addr)
 static void
 printmmsghdr(struct tcb *tcp, long addr, unsigned int idx, unsigned long msg_len)
 {
-	struct mmsghdr {
-		struct msghdr msg_hdr;
-		unsigned msg_len;
-	} mmsg;
+	struct mmsghdr mmsg;
 
 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
 	if (current_wordsize == 4) {
-- 
1.9.3





More information about the Strace-devel mailing list