summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main/fastcgi.c20
-rw-r--r--main/fastcgi.h9
-rw-r--r--sapi/cgi/cgi_main.c9
3 files changed, 31 insertions, 7 deletions
diff --git a/main/fastcgi.c b/main/fastcgi.c
index da66a7ed66..a1e48c4a84 100644
--- a/main/fastcgi.c
+++ b/main/fastcgi.c
@@ -32,6 +32,8 @@
#define MAXFQDNLEN 255
#endif
+static fcgi_logger flog;
+
#ifdef _WIN32
#include <windows.h>
@@ -407,6 +409,10 @@ void fcgi_terminate(void)
in_shutdown = 1;
}
+void fcgi_set_logger(fcgi_logger logger) {
+ flog = logger;
+}
+
int fcgi_init(void)
{
if (!is_initialized) {
@@ -626,10 +632,10 @@ int fcgi_listen(const char *path, int backlog)
hep = gethostbyname(host);
}
if (!hep || hep->h_addrtype != AF_INET || !hep->h_addr_list[0]) {
- fprintf(stderr, "Cannot resolve host name '%s'!\n", host);
+ flog(FCGI_ERROR, "Cannot resolve host name '%s'!\n", host);
return -1;
} else if (hep->h_addr_list[1]) {
- fprintf(stderr, "Host '%s' has multiple addresses. You must choose one explicitly!\n", host);
+ flog(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;
@@ -666,7 +672,7 @@ int fcgi_listen(const char *path, int backlog)
int path_len = strlen(path);
if (path_len >= sizeof(sa.sa_unix.sun_path)) {
- fprintf(stderr, "Listening socket's path name is too long.\n");
+ flog(FCGI_ERROR, "Listening socket's path name is too long.\n");
return -1;
}
@@ -689,7 +695,7 @@ int fcgi_listen(const char *path, int backlog)
bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||
listen(listen_socket, backlog) < 0) {
- fprintf(stderr, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
+ flog(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
return -1;
}
@@ -719,7 +725,7 @@ int fcgi_listen(const char *path, int backlog)
}
allowed_clients[n] = inet_addr(cur);
if (allowed_clients[n] == INADDR_NONE) {
- fprintf(stderr, "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS\n", cur);
+ flog(FCGI_ERROR, "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS\n", cur);
}
n++;
cur = end;
@@ -1229,7 +1235,7 @@ int fcgi_accept_request(fcgi_request *req)
n++;
}
if (!allowed) {
- fprintf(stderr, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr));
+ flog(FCGI_ERROR, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr));
closesocket(req->fd);
req->fd = -1;
continue;
@@ -1287,7 +1293,7 @@ int fcgi_accept_request(fcgi_request *req)
}
fcgi_close(req, 1, 0);
} else {
- fprintf(stderr, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
+ flog(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 fa98730220..b7fa210bfe 100644
--- a/main/fastcgi.h
+++ b/main/fastcgi.h
@@ -49,6 +49,12 @@ typedef enum _fcgi_role {
FCGI_FILTER = 3
} fcgi_role;
+typedef enum _fcgi_code {
+ FCGI_NOTICE,
+ FCGI_WARNING,
+ FCGI_ERROR,
+} fcgi_code;
+
typedef enum _fcgi_request_type {
FCGI_BEGIN_REQUEST = 1, /* [in] */
FCGI_ABORT_REQUEST = 2, /* [in] (not supported) */
@@ -110,6 +116,8 @@ 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 *format, ...);
+
typedef struct _fcgi_request fcgi_request;
int fcgi_init(void);
@@ -122,6 +130,7 @@ fcgi_request* fcgi_init_request(int listen_socket);
void fcgi_destroy_request(fcgi_request *req);
int fcgi_accept_request(fcgi_request *req);
int fcgi_finish_request(fcgi_request *req, int force_close);
+void fcgi_set_logger(fcgi_logger logger);
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);
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c
index b479d4df4e..a60b7c22a9 100644
--- a/sapi/cgi/cgi_main.c
+++ b/sapi/cgi/cgi_main.c
@@ -219,6 +219,14 @@ static php_cgi_globals_struct php_cgi_globals;
#define TRANSLATE_SLASHES(path)
#endif
+static void fcgi_log(int type, const char *format, ...) {
+ va_list ap;
+
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+}
+
static int print_module_info(zval *element)
{
zend_module_entry *module = Z_PTR_P(element);
@@ -1928,6 +1936,7 @@ consult the installation file that came with this distribution, or visit \n\
}
}
+ fcgi_set_logger(fcgi_log);
if (bindpath) {
int backlog = 128;
if (getenv("PHP_FCGI_BACKLOG")) {