]> granicus.if.org Git - strace/blob - tests/accept.c
Remove XLAT_END
[strace] / tests / accept.c
1 /*
2  * Check decoding of accept syscall.
3  *
4  * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
5  * Copyright (c) 2016-2019 The strace developers.
6  * All rights reserved.
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include "tests.h"
12
13 #include <unistd.h>
14
15 #include "scno.h"
16
17 #if defined __NR_accept
18
19 # ifndef TEST_SYSCALL_NAME
20 #  define TEST_SYSCALL_NAME do_accept
21
22 #  ifndef TEST_SYSCALL_STR
23 #   define TEST_SYSCALL_STR "accept"
24 #  endif
25
26 int do_accept(int sockfd, void *addr, void *addrlen)
27 {
28         return syscall(__NR_accept, sockfd, addr, addrlen);
29 }
30 # endif /* !TEST_SYSCALL_NAME */
31
32 #else /* !__NR_accept */
33
34 # ifndef TEST_SYSCALL_NAME
35 #  define TEST_SYSCALL_NAME accept
36 # endif
37
38 #endif /* __NR_accept */
39
40 #define TEST_SYSCALL_PREPARE connect_un()
41 static void connect_un(void);
42 #include "sockname.c"
43
44 static void
45 connect_un(void)
46 {
47         int cfd = socket(AF_UNIX, SOCK_STREAM, 0);
48         if (cfd < 0)
49                 perror_msg_and_skip("socket");
50
51         struct sockaddr_un un = {
52                 .sun_family = AF_UNIX,
53                 .sun_path = TEST_SOCKET ".connect"
54         };
55
56         (void) unlink(un.sun_path);
57         if (bind(cfd, (const void *) &un, sizeof(un)))
58                 perror_msg_and_skip("bind");
59         (void) unlink(un.sun_path);
60
61         un.sun_path[sizeof(TEST_SOCKET) - 1] = '\0';
62         if (connect(cfd, (const void *) &un, sizeof(un)))
63                 perror_msg_and_skip("connect");
64 }
65
66 int
67 main(void)
68 {
69         int lfd = socket(AF_UNIX, SOCK_STREAM, 0);
70         if (lfd < 0)
71                 perror_msg_and_skip("socket");
72
73         (void) unlink(TEST_SOCKET);
74
75         const struct sockaddr_un un = {
76                 .sun_family = AF_UNIX,
77                 .sun_path = TEST_SOCKET
78         };
79
80         if (bind(lfd, (const void *) &un, sizeof(un)))
81                 perror_msg_and_skip("bind");
82         if (listen(lfd, 16))
83                 perror_msg_and_skip("listen");
84
85         test_sockname_syscall(lfd);
86
87         (void) unlink(TEST_SOCKET);
88
89         puts("+++ exited with 0 +++");
90         return 0;
91 }