com php-src: Use weak function for fcgi_log: Zend/zend_ portability.h main/fastcgi.c main/fastcgi.h sapi/cg i/cgi_main.c sapi/fpm/fpm/fpm_main.c
| From: | Xinchen Hui | Date: | Sat, 23 May 2015 11:19:48 +0000 |
| Subject: | com php-src: Use weak function for fcgi_log: Zend/zend_ portability.h main/fastcgi.c main/fastcgi.h sapi/cg i/cgi_main.c sapi/fpm/fpm/fpm_main.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86956@lists.php.net to get a copy of this message | ||
Commit: 86de98cabada88f4667839794c176ea37648498b
Author: Xinchen Hui <laruence@gmail.com> Sat, 23 May 2015 19:19:48 +0800
Parents: 18cf4e0a8a574034f60f4d123407c173e57e54ec
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=86de98cabada88f4667839794c176ea37648498b
Log:
Use weak function for fcgi_log
Changed paths:
M Zend/zend_portability.h
M main/fastcgi.c
M main/fastcgi.h
M sapi/cgi/cgi_main.c
M sapi/fpm/fpm/fpm_main.c
Diff:
diff --git a/Zend/zend_portability.h b/Zend/zend_portability.h
index eca9c83..65455ee 100644
--- a/Zend/zend_portability.h
+++ b/Zend/zend_portability.h
@@ -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
diff --git a/main/fastcgi.c b/main/fastcgi.c
index 8bc4d27..356aa1d 100644
--- a/main/fastcgi.c
+++ b/main/fastcgi.c
@@ -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
diff --git a/main/fastcgi.h b/main/fastcgi.h
index b8ff9ba..079c25a 100644
--- a/main/fastcgi..h
+++ b/main/fastcgi.h
@@ -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);
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index b89829f..fd8f665 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -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")) {
diff --git a/sapi/fpm/fpm/fpm_main.c b/sapi/fpm/fpm/fpm_main.c
index d861c3b..02ca575 100644
--- a/sapi/fpm/fpm/fpm_main.c
+++ b/sapi/fpm/fpm/fpm_main.c
@@ -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