@@ -593,6 +593,7 @@ setsockopt_t setsockopt_f = NULL;
593593dup_t dup_f = NULL ;
594594dup2_t dup2_f = NULL ;
595595dup3_t dup3_f = NULL ;
596+ fclose_t fclose_f = NULL ;
596597
597598int connect (int fd, const struct sockaddr *addr, socklen_t addrlen)
598599{
@@ -1110,6 +1111,12 @@ int dup3(int oldfd, int newfd, int flags)
11101111 return ret;
11111112}
11121113
1114+ int fclose (FILE* fp)
1115+ {
1116+ if (!fclose_f) coroutine_hook_init ();
1117+ return FdManager::getInstance ().fclose (fp);
1118+ }
1119+
11131120#if WITH_CARES
11141121struct hostent * co_gethostbyname2 (const char *name, int af)
11151122{
@@ -1267,6 +1274,7 @@ extern int __dup(int);
12671274extern int __dup2 (int , int );
12681275extern int __dup3 (int , int , int );
12691276extern int __usleep (useconds_t usec);
1277+ extern int __new_fclose (FILE *fp);
12701278
12711279// 某些版本libc.a中没有__usleep.
12721280__attribute__ ((weak))
@@ -1313,6 +1321,7 @@ void coroutine_hook_init()
13131321 dup_f = (dup_t )dlsym (RTLD_NEXT, " dup" );
13141322 dup2_f = (dup2_t )dlsym (RTLD_NEXT, " dup2" );
13151323 dup3_f = (dup3_t )dlsym (RTLD_NEXT, " dup3" );
1324+ fclose_f = (fclose_t )dlsym (RTLD_NEXT, " fclose" );
13161325#else
13171326 connect_f = &__connect;
13181327 read_f = &__read;
@@ -1339,12 +1348,13 @@ void coroutine_hook_init()
13391348 dup_f = &__dup;
13401349 dup2_f = &__dup2;
13411350 dup3_f = &__dup3;
1351+ fclose_f = &__new_fclose;
13421352#endif
13431353
13441354 if (!connect_f || !read_f || !write_f || !readv_f || !writev_f || !send_f
13451355 || !sendto_f || !sendmsg_f || !accept_f || !poll_f || !select_f
13461356 || !sleep_f|| !usleep_f || !nanosleep_f || !close_f || !fcntl_f || !setsockopt_f
1347- || !getsockopt_f || !dup_f || !dup2_f
1357+ || !getsockopt_f || !dup_f || !dup2_f || !fclose_f
13481358 // 老版本linux中没有dup3, 无需校验
13491359 // || !dup3_f
13501360 )
0 commit comments