]> granicus.if.org Git - strace/commitdiff
tests: add compatibility layer for accept call
authorEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 13 Feb 2018 01:03:16 +0000 (02:03 +0100)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 13 Feb 2018 03:12:29 +0000 (03:12 +0000)
Recent glibc (since version 2.26) uses accept4 syscall for implementing
accept call on sparc.  Unfortunately, it's impossible to simply fall
back on raw syscall as it had not been wired up until linux commit
v4.4-rc8~4^2~1.

* tests/accept_compat.h: New file.
* tests/Makefile.am (EXTRA_DIST): Add it.
* tests/net-y-unix.c: Include accept_compat.h, use do_accept()
instead of accept() calls.
* tests/net-yy-inet.c: Likewise.
* tests/net-yy-unix.c: Likewise.
* tests/net.expected: Allow accept4.

tests/Makefile.am
tests/accept_compat.h [new file with mode: 0644]
tests/net-y-unix.c
tests/net-yy-inet.c
tests/net-yy-unix.c
tests/net.expected

index 103a90dde772ffe9c5e18b7a33446b91aa4c9921..3c3d9746eb8e8fb4482179f11bea75cd6dbba522 100644 (file)
@@ -332,6 +332,7 @@ VALGRIND_FLAGS = --quiet
 VALGRIND_SUPPRESSIONS_FILES = $(abs_srcdir)/strace.supp
 
 EXTRA_DIST = \
+       accept_compat.h \
        attach-p-cmd.h \
        caps-abbrev.awk \
        caps.awk \
diff --git a/tests/accept_compat.h b/tests/accept_compat.h
new file mode 100644 (file)
index 0000000..c45b255
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef _STRACE_TESTS_ACCEPT_COMPAT_H_
+#define _STRACE_TESTS_ACCEPT_COMPAT_H_
+
+#include <unistd.h>
+#include <sys/socket.h>
+#include <asm/unistd.h>
+
+#if defined __NR_socketcall && defined __sparc__
+/*
+ * Work around the fact that
+ * - glibc >= 2.26 uses accept4 syscall to implement accept() call on sparc;
+ * - accept syscall had not been wired up on sparc until v4.4-rc8~4^2~1.
+ */
+static inline int
+do_accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
+{
+       const long args[] = { sockfd, (long) addr, (long) addrlen };
+
+       return syscall(__NR_socketcall, 5, args);
+}
+#else
+# define do_accept accept
+#endif
+
+#endif /* !_STRACE_TESTS_ACCEPT_COMPAT_H_ */
index a04cc21d33a729366600de53fbb0837f3e8de137..d32173cb732136c360ea21067d7989b53f40a157 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include "accept_compat.h"
+
 #define TEST_SOCKET "net-y-unix.socket"
 
 int
@@ -105,7 +107,7 @@ main(void)
        struct sockaddr * const accept_sa = tail_alloc(sizeof(addr));
        memset(accept_sa, 0, sizeof(addr));
        *len = sizeof(addr);
-       int accept_fd = accept(listen_fd, accept_sa, len);
+       int accept_fd = do_accept(listen_fd, accept_sa, len);
        if (accept_fd < 0)
                perror_msg_and_fail("accept");
        unsigned long accept_inode = inode_of_sockfd(accept_fd);
@@ -176,7 +178,7 @@ main(void)
 
        memset(accept_sa, 0, sizeof(addr));
        *len = sizeof(addr);
-       accept_fd = accept(listen_fd, accept_sa, len);
+       accept_fd = do_accept(listen_fd, accept_sa, len);
        if (accept_fd < 0)
                perror_msg_and_fail("accept");
        accept_inode = inode_of_sockfd(accept_fd);
index c043920d13c186a32539c08a91250906d6395d35..71f9bac2b1dd7264faa65077029f28cf021881ff 100644 (file)
@@ -39,6 +39,8 @@
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
 
+#include "accept_compat.h"
+
 int
 main(void)
 {
@@ -105,7 +107,7 @@ main(void)
        struct sockaddr * const accept_sa = tail_alloc(sizeof(addr));
        memset(accept_sa, 0, sizeof(addr));
        *len = sizeof(addr);
-       const int accept_fd = accept(listen_fd, accept_sa, len);
+       const int accept_fd = do_accept(listen_fd, accept_sa, len);
        if (accept_fd < 0)
                perror_msg_and_fail("accept");
        const unsigned int connect_port =
index 60c0d494dec3e2824e441bb1ef328fca7a9b4f28..4837c43589fd6debb8109d197aa5e6dd271fb9c1 100644 (file)
@@ -37,6 +37,8 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#include "accept_compat.h"
+
 #define TEST_SOCKET "net-yy-unix.socket"
 
 int
@@ -106,7 +108,7 @@ main(void)
        struct sockaddr * const accept_sa = tail_alloc(sizeof(addr));
        memset(accept_sa, 0, sizeof(addr));
        *len = sizeof(addr);
-       int accept_fd = accept(listen_fd, accept_sa, len);
+       int accept_fd = do_accept(listen_fd, accept_sa, len);
        if (accept_fd < 0)
                perror_msg_and_fail("accept");
        unsigned long accept_inode = inode_of_sockfd(accept_fd);
@@ -179,7 +181,7 @@ main(void)
 
        memset(accept_sa, 0, sizeof(addr));
        *len = sizeof(addr);
-       accept_fd = accept(listen_fd, accept_sa, len);
+       accept_fd = do_accept(listen_fd, accept_sa, len);
        if (accept_fd < 0)
                perror_msg_and_fail("accept");
        accept_inode = inode_of_sockfd(accept_fd);
index 80dd07016e677c6767812fbc83a64c76a6aa33c6..e33e29662b87519602d91de62725a16cb9c60807 100644 (file)
@@ -3,5 +3,5 @@
 [1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +bind\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, 19\) += 0
 [1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +listen\(0, 5\) += 0
 [1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +getsockname\(0, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, \[19\]\) += 0
-[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +accept\(0, \{sa_family=AF_(LOCAL|UNIX|FILE)\}, \[19->2\]\) += 1
+[1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +accept4?\(0, \{sa_family=AF_(LOCAL|UNIX|FILE)\}, \[19->2\](, 0)?\) += 1
 [1-9][0-9]* +[0-9]+:[0-9]+:[0-9]+\.[0-9]+ +connect\(1, \{sa_family=AF_(LOCAL|UNIX|FILE), sun_path="net-local-stream"\}, 19\) += 0