@@ -86,6 +86,11 @@ static int is_sandbox_user() {
8686 }
8787 return 0 ;
8888}
89+ #define RESOLVE_REAL (func ) \
90+ static typeof(func) *real_##func = NULL; \
91+ if (!real_##func) { \
92+ real_##func = dlsym(RTLD_NEXT, #func); \
93+ }
8994/**
9095 * 限制网络访问
9196 */
@@ -190,9 +195,7 @@ static int match_banned_ip(const char *ip_str, const char *rules) {
190195
191196// ------------------ 网络拦截 ------------------
192197int connect (int sockfd , const struct sockaddr * addr , socklen_t addrlen ) {
193- static int (* real_connect )(int , const struct sockaddr * , socklen_t ) = NULL ;
194- if (!real_connect )
195- real_connect = dlsym (RTLD_NEXT , "connect" );
198+ RESOLVE_REAL (connect );
196199 ensure_config_loaded ();
197200 if (is_sandbox_user () && addr -> sa_family == AF_UNIX ) {
198201 struct sockaddr_un * un = (struct sockaddr_un * )addr ;
@@ -227,11 +230,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
227230int getaddrinfo (const char * node , const char * service ,
228231 const struct addrinfo * hints ,
229232 struct addrinfo * * res ) {
230- static int (* real_getaddrinfo )(const char * , const char * ,
231- const struct addrinfo * ,
232- struct addrinfo * * ) = NULL ;
233- if (!real_getaddrinfo )
234- real_getaddrinfo = dlsym (RTLD_NEXT , "getaddrinfo" );
233+ RESOLVE_REAL (getaddrinfo );
235234 ensure_config_loaded ();
236235 if (node && is_sandbox_user ()) {
237236 struct in_addr ip4 ;
@@ -263,11 +262,6 @@ static int not_supported(const char *function_name) {
263262 _exit (126 );
264263 return -1 ;
265264}
266- #define RESOLVE_REAL (func ) \
267- static typeof(func) *real_##func = NULL; \
268- if (!real_##func) { \
269- real_##func = dlsym(RTLD_NEXT, #func); \
270- }
271265int execv (const char * path , char * const argv []) {
272266 RESOLVE_REAL (execv );
273267 if (!allow_create_subprocess ()) return deny ();
0 commit comments