Skip to content

Commit ba5ecf3

Browse files
committed
Use logger pointer
1 parent e383cb4 commit ba5ecf3

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

main/fastcgi.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
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+
410416
int 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

main/fastcgi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ typedef enum _fcgi_role {
4949
FCGI_FILTER = 3
5050
} fcgi_role;
5151

52+
typedef enum _fcgi_code {
53+
FCGI_NOTICE,
54+
FCGI_WARNING,
55+
FCGI_ERROR,
56+
} fcgi_code;
57+
5258
typedef enum _fcgi_request_type {
5359
FCGI_BEGIN_REQUEST = 1, /* [in] */
5460
FCGI_ABORT_REQUEST = 2, /* [in] (not supported) */
@@ -110,6 +116,8 @@ typedef struct _fcgi_end_request_rec {
110116

111117
typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
112118

119+
typedef void (*fcgi_logger)(int type, const char *format, ...);
120+
113121
typedef struct _fcgi_request fcgi_request;
114122

115123
int fcgi_init(void);
@@ -122,6 +130,7 @@ fcgi_request* fcgi_init_request(int listen_socket);
122130
void fcgi_destroy_request(fcgi_request *req);
123131
int fcgi_accept_request(fcgi_request *req);
124132
int fcgi_finish_request(fcgi_request *req, int force_close);
133+
void fcgi_set_logger(fcgi_logger logger);
125134

126135
char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
127136
char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);

sapi/cgi/cgi_main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ static php_cgi_globals_struct php_cgi_globals;
219219
#define TRANSLATE_SLASHES(path)
220220
#endif
221221

222+
static void fcgi_log(int type, const char *format, ...) {
223+
va_list ap;
224+
225+
va_start(ap, format);
226+
vfprintf(stderr, format, ap);
227+
va_end(ap);
228+
}
229+
222230
static int print_module_info(zval *element)
223231
{
224232
zend_module_entry *module = Z_PTR_P(element);
@@ -1928,6 +1936,7 @@ consult the installation file that came with this distribution, or visit \n\
19281936
}
19291937
}
19301938

1939+
fcgi_set_logger(fcgi_log);
19311940
if (bindpath) {
19321941
int backlog = 128;
19331942
if (getenv("PHP_FCGI_BACKLOG")) {

0 commit comments

Comments
 (0)