android-cloexec-accept4.cpp
2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// RUN: %check_clang_tidy %s android-cloexec-accept4 %t
typedef int socklen_t;
struct sockaddr {};
#define SOCK_NONBLOCK 1
#define __O_CLOEXEC 3
#define SOCK_CLOEXEC __O_CLOEXEC
#define TEMP_FAILURE_RETRY(exp) \
({ \
int _rc; \
do { \
_rc = (exp); \
} while (_rc == -1); \
})
#define NULL 0
extern "C" int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
void a() {
accept4(0, NULL, NULL, SOCK_NONBLOCK);
// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: 'accept4' should use SOCK_CLOEXEC where possible [android-cloexec-accept4]
// CHECK-FIXES: accept4(0, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_NONBLOCK));
// CHECK-MESSAGES: :[[@LINE-1]]:58: warning: 'accept4'
// CHECK-FIXES: TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC));
}
void f() {
accept4(0, NULL, NULL, 3);
// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: 'accept4'
// CHECK-FIXES: accept4(0, NULL, NULL, 3 | SOCK_CLOEXEC);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, 3));
// CHECK-MESSAGES: :[[@LINE-1]]:46: warning: 'accept4'
// CHECK-FIXES: TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, 3 | SOCK_CLOEXEC));
int flag = SOCK_NONBLOCK;
accept4(0, NULL, NULL, flag);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, flag));
}
namespace i {
int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
void d() {
accept4(0, NULL, NULL, SOCK_NONBLOCK);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_NONBLOCK));
}
} // namespace i
void e() {
accept4(0, NULL, NULL, SOCK_CLOEXEC);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_CLOEXEC));
accept4(0, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_NONBLOCK | SOCK_CLOEXEC));
}
class G {
public:
int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
void d() {
accept4(0, NULL, NULL, SOCK_NONBLOCK);
TEMP_FAILURE_RETRY(accept4(0, NULL, NULL, SOCK_NONBLOCK));
}
};