@@ -133,7 +133,9 @@ static int is_impersonate = 0;
133133#include "fastcgi.h"
134134
135135/* maybe it's better to use weak name instead */
136- static fcgi_logger logger ;
136+ #ifndef HAVE_ATTRIBUTE_WEAK
137+ static fcgi_logger fcgi_log ;
138+ #endif
137139
138140typedef union _sa_t {
139141 struct sockaddr sa ;
@@ -360,9 +362,19 @@ void fcgi_terminate(void)
360362 in_shutdown = 1 ;
361363}
362364
365+ #ifndef HAVE_ATTRIBUTE_WEAK
363366void fcgi_set_logger (fcgi_logger lg ) {
364- logger = lg ;
367+ fcgi_log = lg ;
365368}
369+ #else
370+ void __attribute__((weak )) fcgi_log (int type , const char * format , ...) {
371+ va_list ap ;
372+
373+ va_start (ap , format );
374+ vfprintf (stderr , format , ap );
375+ va_end (ap );
376+ }
377+ #endif
366378
367379int fcgi_init (void )
368380{
@@ -583,10 +595,10 @@ int fcgi_listen(const char *path, int backlog)
583595 hep = gethostbyname (host );
584596 }
585597 if (!hep || hep -> h_addrtype != AF_INET || !hep -> h_addr_list [0 ]) {
586- logger (FCGI_ERROR , "Cannot resolve host name '%s'!\n" , host );
598+ fcgi_log (FCGI_ERROR , "Cannot resolve host name '%s'!\n" , host );
587599 return -1 ;
588600 } else if (hep -> h_addr_list [1 ]) {
589- logger (FCGI_ERROR , "Host '%s' has multiple addresses. You must choose one explicitly!\n" , host );
601+ fcgi_log (FCGI_ERROR , "Host '%s' has multiple addresses. You must choose one explicitly!\n" , host );
590602 return -1 ;
591603 }
592604 sa .sa_inet .sin_addr .s_addr = ((struct in_addr * )hep -> h_addr_list [0 ])-> s_addr ;
@@ -623,7 +635,7 @@ int fcgi_listen(const char *path, int backlog)
623635 int path_len = strlen (path );
624636
625637 if (path_len >= sizeof (sa .sa_unix .sun_path )) {
626- logger (FCGI_ERROR , "Listening socket's path name is too long.\n" );
638+ fcgi_log (FCGI_ERROR , "Listening socket's path name is too long.\n" );
627639 return -1 ;
628640 }
629641
@@ -646,7 +658,7 @@ int fcgi_listen(const char *path, int backlog)
646658 bind (listen_socket , (struct sockaddr * ) & sa , sock_len ) < 0 ||
647659 listen (listen_socket , backlog ) < 0 ) {
648660
649- logger (FCGI_ERROR , "Cannot bind/listen socket - [%d] %s.\n" ,errno , strerror (errno ));
661+ fcgi_log (FCGI_ERROR , "Cannot bind/listen socket - [%d] %s.\n" ,errno , strerror (errno ));
650662 return -1 ;
651663 }
652664
@@ -683,14 +695,14 @@ int fcgi_listen(const char *path, int backlog)
683695 n ++ ;
684696#endif
685697 } else {
686- logger (FCGI_ERROR , "Wrong IP address '%s' in listen.allowed_clients" , cur );
698+ fcgi_log (FCGI_ERROR , "Wrong IP address '%s' in listen.allowed_clients" , cur );
687699 }
688700 cur = end ;
689701 }
690702 allowed_clients [n ].sa .sa_family = 0 ;
691703 free (ip );
692704 if (!n ) {
693- logger (FCGI_ERROR , "There are no allowed addresses" );
705+ fcgi_log (FCGI_ERROR , "There are no allowed addresses" );
694706 /* don't clear allowed_clients as it will create an "open for all" security issue */
695707 }
696708 }
@@ -743,14 +755,14 @@ void fcgi_set_allowed_clients(char *ip)
743755 n ++ ;
744756#endif
745757 } else {
746- logger (FCGI_ERROR , "Wrong IP address '%s' in listen.allowed_clients" , cur );
758+ fcgi_log (FCGI_ERROR , "Wrong IP address '%s' in listen.allowed_clients" , cur );
747759 }
748760 cur = end ;
749761 }
750762 allowed_clients [n ].sa .sa_family = 0 ;
751763 free (ip );
752764 if (!n ) {
753- logger (FCGI_ERROR , "There are no allowed addresses" );
765+ fcgi_log (FCGI_ERROR , "There are no allowed addresses" );
754766 /* don't clear allowed_clients as it will create an "open for all" security issue */
755767 }
756768 }
@@ -1222,7 +1234,7 @@ static int fcgi_is_allowed() {
12221234 }
12231235#endif
12241236
1225- logger (FCGI_ERROR , "Connection disallowed: IP address '%s' has been dropped." , fcgi_get_last_client_ip ());
1237+ fcgi_log (FCGI_ERROR , "Connection disallowed: IP address '%s' has been dropped." , fcgi_get_last_client_ip ());
12261238 return 0 ;
12271239}
12281240
@@ -1337,7 +1349,7 @@ int fcgi_accept_request(fcgi_request *req)
13371349 }
13381350 fcgi_close (req , 1 , 0 );
13391351 } else {
1340- logger (FCGI_ERROR , "Too many open file descriptors. FD_SETSIZE limit exceeded." );
1352+ fcgi_log (FCGI_ERROR , "Too many open file descriptors. FD_SETSIZE limit exceeded." );
13411353 fcgi_close (req , 1 , 0 );
13421354 }
13431355#endif
0 commit comments