]> granicus.if.org Git - strace/commitdiff
mmsg.test: prefer direct sendmmsg/recvmmsg syscalls to libc wrappers
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 11 Jan 2016 00:16:39 +0000 (00:16 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 11 Jan 2016 01:03:19 +0000 (01:03 +0000)
* tests/mmsg.c: Include <sys/syscall.h>.
Check for __NR_sendmmsg as an alternative to HAVE_SENDMMSG.
[!HAVE_STRUCT_MMSGHDR] (struct mmsghdr): Define.
(send_mmsg, recv_mmsg): New functions.
(main): Use them instead of sendmmsg and recvmmsg.

Reported-by: Szabolcs Nagy <nsz@port70.net>
tests/mmsg.c

index b67279528c7c029fec0c17e61fe37710ba9563e1..e3e84357e8a48d277e886cce1ee0b000b42952c8 100644 (file)
@@ -27,8 +27,9 @@
  */
 
 #include "tests.h"
+# include <sys/syscall.h>
 
-#if defined(HAVE_SENDMMSG) && defined(HAVE_STRUCT_MMSGHDR)
+#if defined __NR_sendmmsg || defined HAVE_SENDMMSG
 
 # include <assert.h>
 # include <errno.h>
 # include <unistd.h>
 # include <sys/socket.h>
 
+#ifndef HAVE_STRUCT_MMSGHDR
+struct mmsghdr {
+       struct msghdr msg_hdr;
+       unsigned msg_len;
+};
+#endif
+
+static int
+send_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags)
+{
+       int rc;
+#ifdef __NR_sendmmsg
+       rc = syscall(__NR_sendmmsg, (long) fd, vec, (unsigned long) vlen,
+                    (unsigned long) flags);
+       if (rc >= 0 || ENOSYS != errno)
+               return rc;
+#endif
+#ifdef HAVE_SENDMMSG
+       rc = sendmmsg(fd, vec, vlen, flags);
+#endif
+       return rc;
+}
+
+static int
+recv_mmsg(int fd, struct mmsghdr *vec, unsigned int vlen, unsigned int flags,
+         struct timespec *timeout)
+{
+       int rc;
+#ifdef __NR_sendmmsg
+       rc = syscall(__NR_recvmmsg, (long) fd, vec, (unsigned long) vlen,
+                    (unsigned long) flags, timeout);
+       if (rc >= 0 || ENOSYS != errno)
+               return rc;
+#endif
+#ifdef HAVE_SENDMMSG
+       rc = recvmmsg(fd, vec, vlen, flags, timeout);
+#endif
+       return rc;
+}
+
 int
 main(void)
 {
@@ -91,13 +132,13 @@ main(void)
        assert(dup2(sv[R], R) == R);
        assert(close(sv[R]) == 0);
 
-       int r = sendmmsg(W, mmh, n_mmh, 0);
+       int r = send_mmsg(W, mmh, n_mmh, 0);
        if (r < 0 && errno == ENOSYS)
                perror_msg_and_skip("sendmmsg");
        assert((size_t)r == n_mmh);
        assert(close(W) == 0);
 
-       assert(recvmmsg(R, mmh, n_mmh, 0, NULL) == n_mmh);
+       assert(recv_mmsg(R, mmh, n_mmh, 0, NULL) == n_mmh);
        assert(close(R) == 0);
 
        return 0;
@@ -105,6 +146,6 @@ main(void)
 
 #else
 
-SKIP_MAIN_UNDEFINED("HAVE_SENDMMSG && HAVE_STRUCT_MMSGHDR")
+SKIP_MAIN_UNDEFINED("__NR_sendmmsg || HAVE_SENDMMSG")
 
 #endif