]> granicus.if.org Git - php/commitdiff
Use weak function for fcgi_log
authorXinchen Hui <laruence@gmail.com>
Sat, 23 May 2015 11:19:48 +0000 (19:19 +0800)
committerXinchen Hui <laruence@gmail.com>
Sat, 23 May 2015 11:19:48 +0000 (19:19 +0800)
Zend/zend_portability.h
main/fastcgi.c
main/fastcgi.h
sapi/cgi/cgi_main.c
sapi/fpm/fpm/fpm_main.c

index eca9c83f89f896620552fa9eb6f884b23806fb4e..65455ee10f6f17207d9e21a43d02cea67aa308c5 100644 (file)
@@ -240,6 +240,7 @@ char *alloca();
 
 #if (defined(__GNUC__) && __GNUC__ >= 3 && !defined(__INTEL_COMPILER) && !defined(DARWIN) && !defined(__hpux) && !defined(_AIX) && !defined(__osf__))
 # define HAVE_NORETURN_ALIAS
+# define HAVE_ATTRIBUTE_WEAK
 #endif
 
 #if ZEND_DEBUG
index 8bc4d2784f68f552bfa814d9b490be4409ceab34..356aa1d56d1ba885a18215a0a2e0e3ab5baa090f 100644 (file)
@@ -133,7 +133,9 @@ static int is_impersonate = 0;
 #include "fastcgi.h"
 
 /* maybe it's better to use weak name instead */
-static fcgi_logger logger;
+#ifndef HAVE_ATTRIBUTE_WEAK
+static fcgi_logger fcgi_log;
+#endif
 
 typedef union _sa_t {
        struct sockaddr     sa;
@@ -360,9 +362,19 @@ void fcgi_terminate(void)
        in_shutdown = 1;
 }
 
+#ifndef HAVE_ATTRIBUTE_WEAK
 void fcgi_set_logger(fcgi_logger lg) {
-       logger = lg;
+       fcgi_log = lg;
 }
+#else
+void __attribute__((weak)) fcgi_log(int type, const char *format, ...) {
+       va_list ap;
+
+       va_start(ap, format);
+       vfprintf(stderr, format, ap);
+       va_end(ap);
+}
+#endif
 
 int fcgi_init(void)
 {
@@ -583,10 +595,10 @@ int fcgi_listen(const char *path, int backlog)
                                        hep = gethostbyname(host);
                                }
                                if (!hep || hep->h_addrtype != AF_INET || !hep->h_addr_list[0]) {
-                                       logger(FCGI_ERROR, "Cannot resolve host name '%s'!\n", host);
+                                       fcgi_log(FCGI_ERROR, "Cannot resolve host name '%s'!\n", host);
                                        return -1;
                                } else if (hep->h_addr_list[1]) {
-                                       logger(FCGI_ERROR, "Host '%s' has multiple addresses. You must choose one explicitly!\n", host);
+                                       fcgi_log(FCGI_ERROR, "Host '%s' has multiple addresses. You must choose one explicitly!\n", host);
                                        return -1;
                                }
                                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)
                int path_len = strlen(path);
 
                if (path_len >= sizeof(sa.sa_unix.sun_path)) {
-                       logger(FCGI_ERROR, "Listening socket's path name is too long.\n");
+                       fcgi_log(FCGI_ERROR, "Listening socket's path name is too long.\n");
                        return -1;
                }
 
@@ -646,7 +658,7 @@ int fcgi_listen(const char *path, int backlog)
            bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||
            listen(listen_socket, backlog) < 0) {
 
-               logger(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
+               fcgi_log(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
                return -1;
        }
 
@@ -683,14 +695,14 @@ int fcgi_listen(const char *path, int backlog)
                                        n++;
 #endif
                                } else {
-                                       logger(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
+                                       fcgi_log(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
                                }
                                cur = end;
                        }
                        allowed_clients[n].sa.sa_family = 0;
                        free(ip);
                        if (!n) {
-                               logger(FCGI_ERROR, "There are no allowed addresses");
+                               fcgi_log(FCGI_ERROR, "There are no allowed addresses");
                                /* don't clear allowed_clients as it will create an "open for all" security issue */
                        }
                }
@@ -743,14 +755,14 @@ void fcgi_set_allowed_clients(char *ip)
                                n++;
 #endif
                        } else {
-                               logger(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
+                               fcgi_log(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
                        }
                        cur = end;
                }
                allowed_clients[n].sa.sa_family = 0;
                free(ip);
                if (!n) {
-                       logger(FCGI_ERROR, "There are no allowed addresses");
+                       fcgi_log(FCGI_ERROR, "There are no allowed addresses");
                        /* don't clear allowed_clients as it will create an "open for all" security issue */
                }
        }
@@ -1222,7 +1234,7 @@ static int fcgi_is_allowed() {
        }
 #endif
 
-       logger(FCGI_ERROR, "Connection disallowed: IP address '%s' has been dropped.", fcgi_get_last_client_ip());
+       fcgi_log(FCGI_ERROR, "Connection disallowed: IP address '%s' has been dropped.", fcgi_get_last_client_ip());
        return 0;
 }
 
@@ -1337,7 +1349,7 @@ int fcgi_accept_request(fcgi_request *req)
                                                }
                                                fcgi_close(req, 1, 0);
                                        } else {
-                                               logger(FCGI_ERROR, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
+                                               fcgi_log(FCGI_ERROR, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
                                                fcgi_close(req, 1, 0);
                                        }
 #endif
index b8ff9ba1230f4dc5fabfc57963b89dacecaea7a8..079c25a011148cee6c85a3e0c76c0956d32f64b3 100644 (file)
@@ -118,8 +118,6 @@ typedef struct _fcgi_end_request_rec {
 
 typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
 
-typedef void (*fcgi_logger)(int type, const char *fmt, ...);
-
 #define FCGI_HASH_TABLE_SIZE 128
 #define FCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1)
 #define FCGI_HASH_SEG_SIZE   4096
@@ -200,10 +198,14 @@ fcgi_request* fcgi_init_request(fcgi_request *request, int listen_socket);
 void fcgi_set_allowed_clients(char *ip);
 int fcgi_accept_request(fcgi_request *req);
 int fcgi_finish_request(fcgi_request *req, int force_close);
-void fcgi_set_logger(fcgi_logger lg);
 const char *fcgi_get_last_client_ip();
 void fcgi_set_in_shutdown(int new_value);
 
+#ifndef HAVE_ATTRIBUTE_WEAK
+typedef void (*fcgi_logger)(int type, const char *fmt, ...);
+void fcgi_set_logger(fcgi_logger lg);
+#endif
+
 char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
 char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
 char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value);
index b89829f0160dd20bf995b8cefd7d429b2f6984f8..fd8f66593697fb810b73a68b2a49f925fd4fa5f6 100644 (file)
@@ -219,6 +219,7 @@ static php_cgi_globals_struct php_cgi_globals;
 #define TRANSLATE_SLASHES(path)
 #endif
 
+#ifndef HAVE_ATTRIBUTE_WEAK
 static void fcgi_log(int type, const char *format, ...) {
        va_list ap;
 
@@ -226,6 +227,7 @@ static void fcgi_log(int type, const char *format, ...) {
        vfprintf(stderr, format, ap);
        va_end(ap);
 }
+#endif
 
 static int print_module_info(zval *element)
 {
@@ -1936,7 +1938,10 @@ consult the installation file that came with this distribution, or visit \n\
                }
        }
 
+#ifndef HAVE_ATTRIBUTE_WEAK
        fcgi_set_logger(fcgi_log);
+#endif
+
        if (bindpath) {
                int backlog = 128;
                if (getenv("PHP_FCGI_BACKLOG")) {
index d861c3beeefc5b3ab53bfd8bbe6818b916f87efe..02ca575ca742db84501ad7d030e00d3d96b52243 100644 (file)
@@ -457,7 +457,11 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */
 # define STDIN_FILENO 0
 #endif
 
+#ifndef HAVE_ATTRIBUTE_WEAK
 static void fpm_fcgi_log(int type, const char *fmt, ...) /* {{{ */
+#else
+void fcgi_log(int type, const char *fmt, ...)
+#endif
 {
        va_list args;
        va_start(args, fmt);
@@ -1586,7 +1590,10 @@ int main(int argc, char *argv[])
        cgi_sapi_module.php_ini_path_override = NULL;
        cgi_sapi_module.php_ini_ignore_cwd = 1;
 
+#ifndef HAVE_ATTRIBUTE_WEAK
        fcgi_set_logger(fpm_fcgi_log);
+#endif
+
        fcgi_init();
 
 #ifdef PHP_WIN32