From: Eugene Syromyatnikov Date: Tue, 13 Feb 2018 01:03:16 +0000 (+0100) Subject: tests: add compatibility layer for accept call X-Git-Tag: v4.21~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=46c6c7d7762c0a65fd09f5893caa4ed76ba0fb64;p=strace tests: add compatibility layer for accept call 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. --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 103a90dd..3c3d9746 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..c45b2551 --- /dev/null +++ b/tests/accept_compat.h @@ -0,0 +1,25 @@ +#ifndef _STRACE_TESTS_ACCEPT_COMPAT_H_ +#define _STRACE_TESTS_ACCEPT_COMPAT_H_ + +#include +#include +#include + +#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_ */ diff --git a/tests/net-y-unix.c b/tests/net-y-unix.c index a04cc21d..d32173cb 100644 --- a/tests/net-y-unix.c +++ b/tests/net-y-unix.c @@ -37,6 +37,8 @@ #include #include +#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); diff --git a/tests/net-yy-inet.c b/tests/net-yy-inet.c index c043920d..71f9bac2 100644 --- a/tests/net-yy-inet.c +++ b/tests/net-yy-inet.c @@ -39,6 +39,8 @@ #include #include +#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 = diff --git a/tests/net-yy-unix.c b/tests/net-yy-unix.c index 60c0d494..4837c435 100644 --- a/tests/net-yy-unix.c +++ b/tests/net-yy-unix.c @@ -37,6 +37,8 @@ #include #include +#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); diff --git a/tests/net.expected b/tests/net.expected index 80dd0701..e33e2966 100644 --- a/tests/net.expected +++ b/tests/net.expected @@ -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