3232#define MAXFQDNLEN 255
3333#endif
3434
35+ static fcgi_logger flog ;
36+
3537#ifdef _WIN32
3638
3739#include <windows.h>
@@ -407,6 +409,10 @@ void fcgi_terminate(void)
407409 in_shutdown = 1 ;
408410}
409411
412+ void fcgi_set_logger (fcgi_logger logger ) {
413+ flog = logger ;
414+ }
415+
410416int fcgi_init (void )
411417{
412418 if (!is_initialized ) {
@@ -626,10 +632,10 @@ int fcgi_listen(const char *path, int backlog)
626632 hep = gethostbyname (host );
627633 }
628634 if (!hep || hep -> h_addrtype != AF_INET || !hep -> h_addr_list [0 ]) {
629- fprintf ( stderr , "Cannot resolve host name '%s'!\n" , host );
635+ flog ( FCGI_ERROR , "Cannot resolve host name '%s'!\n" , host );
630636 return -1 ;
631637 } else if (hep -> h_addr_list [1 ]) {
632- fprintf ( stderr , "Host '%s' has multiple addresses. You must choose one explicitly!\n" , host );
638+ flog ( FCGI_ERROR , "Host '%s' has multiple addresses. You must choose one explicitly!\n" , host );
633639 return -1 ;
634640 }
635641 sa .sa_inet .sin_addr .s_addr = ((struct in_addr * )hep -> h_addr_list [0 ])-> s_addr ;
@@ -666,7 +672,7 @@ int fcgi_listen(const char *path, int backlog)
666672 int path_len = strlen (path );
667673
668674 if (path_len >= sizeof (sa .sa_unix .sun_path )) {
669- fprintf ( stderr , "Listening socket's path name is too long.\n" );
675+ flog ( FCGI_ERROR , "Listening socket's path name is too long.\n" );
670676 return -1 ;
671677 }
672678
@@ -689,7 +695,7 @@ int fcgi_listen(const char *path, int backlog)
689695 bind (listen_socket , (struct sockaddr * ) & sa , sock_len ) < 0 ||
690696 listen (listen_socket , backlog ) < 0 ) {
691697
692- fprintf ( stderr , "Cannot bind/listen socket - [%d] %s.\n" ,errno , strerror (errno ));
698+ flog ( FCGI_ERROR , "Cannot bind/listen socket - [%d] %s.\n" ,errno , strerror (errno ));
693699 return -1 ;
694700 }
695701
@@ -719,7 +725,7 @@ int fcgi_listen(const char *path, int backlog)
719725 }
720726 allowed_clients [n ] = inet_addr (cur );
721727 if (allowed_clients [n ] == INADDR_NONE ) {
722- fprintf ( stderr , "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS\n" , cur );
728+ flog ( FCGI_ERROR , "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS\n" , cur );
723729 }
724730 n ++ ;
725731 cur = end ;
@@ -1229,7 +1235,7 @@ int fcgi_accept_request(fcgi_request *req)
12291235 n ++ ;
12301236 }
12311237 if (!allowed ) {
1232- fprintf ( stderr , "Connection from disallowed IP address '%s' is dropped.\n" , inet_ntoa (sa .sa_inet .sin_addr ));
1238+ flog ( FCGI_ERROR , "Connection from disallowed IP address '%s' is dropped.\n" , inet_ntoa (sa .sa_inet .sin_addr ));
12331239 closesocket (req -> fd );
12341240 req -> fd = -1 ;
12351241 continue ;
@@ -1287,7 +1293,7 @@ int fcgi_accept_request(fcgi_request *req)
12871293 }
12881294 fcgi_close (req , 1 , 0 );
12891295 } else {
1290- fprintf ( stderr , "Too many open file descriptors. FD_SETSIZE limit exceeded." );
1296+ flog ( FCGI_ERROR , "Too many open file descriptors. FD_SETSIZE limit exceeded." );
12911297 fcgi_close (req , 1 , 0 );
12921298 }
12931299#endif
0 commit comments