Skip to content

Commit 3d10c57

Browse files
author
Jérôme Loyet
committed
- enhanced log messages
- code cosmetic
1 parent 02581a0 commit 3d10c57

24 files changed

+112
-109
lines changed

sapi/fpm/fpm/fastcgi.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#include <limits.h>
3030

3131
#include <php_config.h>
32-
#include <fpm/fpm.h>
33-
#include <fpm/fpm_request.h>
32+
#include "fpm.h"
33+
#include "fpm_request.h"
34+
#include "zlog.h"
3435

3536
#ifdef _WIN32
3637

@@ -267,7 +268,7 @@ void fcgi_set_allowed_clients(char *ip)
267268
}
268269
allowed_clients[n] = inet_addr(cur);
269270
if (allowed_clients[n] == INADDR_NONE) {
270-
fprintf(stderr, "Wrong IP address '%s' in FCGI_WEB_SERVER_ADDRS or listen.allowed_clients\n", cur);
271+
zlog(ZLOG_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
271272
}
272273
n++;
273274
cur = end;
@@ -815,7 +816,7 @@ int fcgi_accept_request(fcgi_request *req)
815816
n++;
816817
}
817818
if (!allowed) {
818-
fprintf(stderr, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr));
819+
zlog(ZLOG_ERROR, "Connection disallowed: IP address '%s' has been dropped.", inet_ntoa(sa.sa_inet.sin_addr));
819820
closesocket(req->fd);
820821
req->fd = -1;
821822
continue;
@@ -871,7 +872,7 @@ int fcgi_accept_request(fcgi_request *req)
871872
}
872873
fcgi_close(req, 1, 0);
873874
} else {
874-
fprintf(stderr, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
875+
zlog(ZLOG_ERROR, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
875876
fcgi_close(req, 1, 0);
876877
}
877878
#endif

sapi/fpm/fpm/fpm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ int fpm_init(int argc, char **argv, char *config, char *prefix, char *pid, int t
6565
if (fpm_globals.test_successful) {
6666
exit(0);
6767
} else {
68+
zlog(ZLOG_ERROR, "FPM initialization failed");
6869
return -1;
6970
}
7071
}
7172

7273
if (0 > fpm_conf_write_pid()) {
74+
zlog(ZLOG_ERROR, "FPM initialization failed");
7375
return -1;
7476
}
7577

sapi/fpm/fpm/fpm_children.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@ static void fpm_child_init(struct fpm_worker_pool_s *wp) /* {{{ */
147147
{
148148
fpm_globals.max_requests = wp->config->pm_max_requests;
149149

150-
if (0 > fpm_stdio_init_child(wp) ||
151-
0 > fpm_log_init_child(wp) ||
152-
0 > fpm_status_init_child(wp) ||
153-
0 > fpm_unix_init_child(wp) ||
154-
0 > fpm_signals_init_child() ||
155-
0 > fpm_env_init_child(wp) ||
156-
0 > fpm_php_init_child(wp)) {
150+
if (0 > fpm_stdio_init_child(wp) ||
151+
0 > fpm_log_init_child(wp) ||
152+
0 > fpm_status_init_child(wp) ||
153+
0 > fpm_unix_init_child(wp) ||
154+
0 > fpm_signals_init_child() ||
155+
0 > fpm_env_init_child(wp) ||
156+
0 > fpm_php_init_child(wp)) {
157157

158158
zlog(ZLOG_ERROR, "[pool %s] child failed to initialize", wp->config->name);
159159
exit(255);
@@ -292,7 +292,7 @@ void fpm_children_bury() /* {{{ */
292292
}
293293
}
294294
} else {
295-
zlog(ZLOG_ALERT, "oops, unknown child (%d) exited %s", pid, buf);
295+
zlog(ZLOG_ALERT, "oops, unknown child (%d) exited %s. Please open a bug report (https://bugs.php.net).", pid, buf);
296296
}
297297
}
298298
}
@@ -305,7 +305,7 @@ static struct fpm_child_s *fpm_resources_prepare(struct fpm_worker_pool_s *wp) /
305305
c = fpm_child_alloc();
306306

307307
if (!c) {
308-
zlog(ZLOG_ERROR, "[pool %s] malloc failed", wp->config->name);
308+
zlog(ZLOG_ERROR, "[pool %s] unable to malloc new child", wp->config->name);
309309
return 0;
310310
}
311311

sapi/fpm/fpm/fpm_cleanup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include "fpm_arrays.h"
1010
#include "fpm_cleanup.h"
11-
#include "zlog.h"
1211

1312
struct cleanup_s {
1413
int type;

sapi/fpm/fpm/fpm_conf.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
#define STR2STR(a) (a ? a : "undefined")
4949
#define BOOL2STR(a) (a ? "yes" : "no")
50-
#define PM2STR(a) (a == PM_STYLE_STATIC ? "static" : "dynamic")
5150
#define GO(field) offsetof(struct fpm_global_config_s, field)
5251
#define WPO(field) offsetof(struct fpm_worker_pool_config_s, field)
5352

@@ -680,7 +679,7 @@ static int fpm_conf_process_all_pools() /* {{{ */
680679
struct fpm_worker_pool_s *wp;
681680

682681
if (!fpm_worker_all_pools) {
683-
zlog(ZLOG_ERROR, "at least one pool section must be specified in config file");
682+
zlog(ZLOG_ERROR, "No pool defined. at least one pool section must be specified in config file");
684683
return -1;
685684
}
686685

@@ -742,8 +741,7 @@ static int fpm_conf_process_all_pools() /* {{{ */
742741

743742
if (config->pm_min_spare_servers > config->pm_max_children ||
744743
config->pm_max_spare_servers > config->pm_max_children) {
745-
zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) and pm.max_spare_servers(%d) cannot be greater than pm.max_children(%d)",
746-
wp->config->name, config->pm_min_spare_servers, config->pm_max_spare_servers, config->pm_max_children);
744+
zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) and pm.max_spare_servers(%d) cannot be greater than pm.max_children(%d)", wp->config->name, config->pm_min_spare_servers, config->pm_max_spare_servers, config->pm_max_children);
747745
return -1;
748746
}
749747

@@ -755,6 +753,7 @@ static int fpm_conf_process_all_pools() /* {{{ */
755753
if (config->pm_start_servers <= 0) {
756754
config->pm_start_servers = config->pm_min_spare_servers + ((config->pm_max_spare_servers - config->pm_min_spare_servers) / 2);
757755
zlog(ZLOG_WARNING, "[pool %s] pm.start_servers is not set. It's been set to %d.", wp->config->name, config->pm_start_servers);
756+
758757
} else if (config->pm_start_servers < config->pm_min_spare_servers || config->pm_start_servers > config->pm_max_spare_servers) {
759758
zlog(ZLOG_ALERT, "[pool %s] pm.start_servers(%d) must not be less than pm.min_spare_servers(%d) and not greater than pm.max_spare_servers(%d)", wp->config->name, config->pm_start_servers, config->pm_min_spare_servers, config->pm_max_spare_servers);
760759
return -1;
@@ -766,7 +765,6 @@ static int fpm_conf_process_all_pools() /* {{{ */
766765
if (wp->config->pm_status_path && *wp->config->pm_status_path) {
767766
int i;
768767
char *status = wp->config->pm_status_path;
769-
/* struct fpm_status_s fpm_status; */
770768

771769
if (*status != '/') {
772770
zlog(ZLOG_ERROR, "[pool %s] the status path '%s' must start with a '/'", wp->config->name, status);
@@ -860,7 +858,7 @@ static int fpm_conf_process_all_pools() /* {{{ */
860858
fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
861859

862860
if (0 > fd) {
863-
zlog(ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog);
861+
zlog(ZLOG_SYSERROR, "Unable to create or open slowlog(%s)", wp->config->slowlog);
864862
return -1;
865863
}
866864
close(fd);
@@ -876,6 +874,7 @@ static int fpm_conf_process_all_pools() /* {{{ */
876874
zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' must start with a '/'", wp->config->name, wp->config->chroot);
877875
return -1;
878876
}
877+
879878
if (!fpm_conf_is_dir(wp->config->chroot)) {
880879
zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' does not exist or is not a directory", wp->config->name, wp->config->chroot);
881880
return -1;
@@ -993,7 +992,7 @@ int fpm_conf_unlink_pid() /* {{{ */
993992
{
994993
if (fpm_global_config.pid_file) {
995994
if (0 > unlink(fpm_global_config.pid_file)) {
996-
zlog(ZLOG_SYSERROR, "unlink(\"%s\") failed", fpm_global_config.pid_file);
995+
zlog(ZLOG_SYSERROR, "Unable to remove the PID file (%s).", fpm_global_config.pid_file);
997996
return -1;
998997
}
999998
}
@@ -1013,14 +1012,14 @@ int fpm_conf_write_pid() /* {{{ */
10131012
fd = creat(fpm_global_config.pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
10141013

10151014
if (fd < 0) {
1016-
zlog(ZLOG_SYSERROR, "creat(\"%s\") failed", fpm_global_config.pid_file);
1015+
zlog(ZLOG_SYSERROR, "Unable to create the PID file (%s).", fpm_global_config.pid_file);
10171016
return -1;
10181017
}
10191018

10201019
len = sprintf(buf, "%d", (int) fpm_globals.parent_pid);
10211020

10221021
if (len != write(fd, buf, len)) {
1023-
zlog(ZLOG_SYSERROR, "write() failed");
1022+
zlog(ZLOG_SYSERROR, "Unable to write to the PID file.");
10241023
return -1;
10251024
}
10261025
close(fd);
@@ -1355,18 +1354,18 @@ int fpm_conf_load_ini_file(char *filename TSRMLS_DC) /* {{{ */
13551354
int ret = 1;
13561355

13571356
if (!filename || !filename[0]) {
1358-
zlog(ZLOG_ERROR, "Configuration file is empty");
1357+
zlog(ZLOG_ERROR, "configuration filename is empty");
13591358
return -1;
13601359
}
13611360

13621361
fd = open(filename, O_RDONLY, 0);
13631362
if (fd < 0) {
1364-
zlog(ZLOG_ERROR, "Unable to open file '%s', errno=%d", filename, errno);
1363+
zlog(ZLOG_SYSERROR, "failed to open configuration file '%s'", filename);
13651364
return -1;
13661365
}
13671366

13681367
if (ini_recursion++ > 4) {
1369-
zlog(ZLOG_ERROR, "You can include more than 5 files recusively");
1368+
zlog(ZLOG_ERROR, "failed to include more than 5 files recusively");
13701369
return -1;
13711370
}
13721371

sapi/fpm/fpm/fpm_conf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <stdint.h>
99
#include "php.h"
1010

11+
#define PM2STR(a) (a == PM_STYLE_STATIC ? "static" : "dynamic")
12+
1113
#define FPM_CONF_MAX_PONG_LENGTH 64
1214

1315
struct key_value_s;

sapi/fpm/fpm/fpm_env.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "fpm_env.h"
1515
#include "fpm.h"
16-
#include "zlog.h"
1716

1817
#ifndef HAVE_SETPROCTITLE
1918
#ifdef __linux__

sapi/fpm/fpm/fpm_events.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void fpm_got_signal(struct fpm_event_s *ev, short which, void *arg) /* {{
6666

6767
if (res <= 0) {
6868
if (res < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
69-
zlog(ZLOG_SYSERROR, "read() failed");
69+
zlog(ZLOG_SYSERROR, "unable to read from the signal pipe");
7070
}
7171
return;
7272
}
@@ -153,7 +153,7 @@ static int fpm_event_queue_add(struct fpm_event_queue_s **queue, struct fpm_even
153153
}
154154

155155
if (!(elt = malloc(sizeof(struct fpm_event_queue_s)))) {
156-
zlog(ZLOG_SYSERROR, "malloc() failed");
156+
zlog(ZLOG_SYSERROR, "Unable to add the event to queue: malloc() failed");
157157
return -1;
158158
}
159159
elt->prev = NULL;
@@ -232,7 +232,7 @@ int fpm_event_init_main() /* {{{ */
232232
/* malloc the max number of necessary fds for polling */
233233
fpm_event_ufds = malloc(sizeof(php_pollfd) * fpm_event_nfds_max);
234234
if (!fpm_event_ufds) {
235-
zlog(ZLOG_SYSERROR, "malloc() failed");
235+
zlog(ZLOG_SYSERROR, "Error while initializing events: malloc() failed");
236236
return -1;
237237
}
238238

@@ -318,7 +318,7 @@ void fpm_event_loop(int err) /* {{{ */
318318
/* wait for inconming event or timeout */
319319
if ((ret = php_poll2(fpm_event_ufds, i, timeout)) == -1) {
320320
if (errno != EINTR) {
321-
zlog(ZLOG_WARNING, "php_poll2() returns %d", errno);
321+
zlog(ZLOG_SYSERROR, "failed to wait for events: php_poll2()");
322322
}
323323
} else if (ret > 0) {
324324

sapi/fpm/fpm/fpm_log.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ int fpm_log_open(int reopen) /* {{{ */
4444

4545
fd = open(wp->config->access_log, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
4646
if (0 > fd) {
47-
zlog(ZLOG_SYSERROR, "open(\"%s\") failed", wp->config->access_log);
47+
zlog(ZLOG_SYSERROR, "failed to open access log (%s)", wp->config->access_log);
4848
return -1;
4949
}
5050

@@ -124,12 +124,12 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */
124124
if (!test) {
125125
scoreboard = fpm_scoreboard_get();
126126
if (!scoreboard) {
127-
zlog(ZLOG_WARNING, "unable to get scoreboard");
127+
zlog(ZLOG_WARNING, "unable to get scoreboard while preparing the access log");
128128
return -1;
129129
}
130130
proc_p = fpm_scoreboard_proc_acquire(NULL, -1, 0);
131131
if (!proc_p) {
132-
zlog(ZLOG_WARNING, "[pool %s] Unable to acquire shm slot", scoreboard->pool);
132+
zlog(ZLOG_WARNING, "[pool %s] Unable to acquire shm slot while preparing the access log", scoreboard->pool);
133133
return -1;
134134
}
135135
proc = *proc_p;
@@ -147,7 +147,7 @@ int fpm_log_write(char *log_format TSRMLS_DC) /* {{{ */
147147

148148
while (*s != '\0') {
149149
if (len > FPM_LOG_BUFFER) {
150-
zlog(ZLOG_NOTICE, "the log buffer is full (%d). The log request has been truncated.", FPM_LOG_BUFFER);
150+
zlog(ZLOG_NOTICE, "the log buffer is full (%d). The access log request has been truncated.", FPM_LOG_BUFFER);
151151
len = FPM_LOG_BUFFER - 1;
152152
break;
153153
}

sapi/fpm/fpm/fpm_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ int __riscosify_control = __RISCOSIFY_STRICT_UNIX_SPECS;
100100
#include "fastcgi.h"
101101

102102
#include <php_config.h>
103-
#include <fpm/fpm.h>
104-
#include <fpm/fpm_request.h>
105-
#include <fpm/fpm_status.h>
106-
#include <fpm/fpm_conf.h>
107-
#include <fpm/fpm_php.h>
108-
#include <fpm/fpm_log.h>
109-
#include <fpm/zlog.h>
103+
#include "fpm.h"
104+
#include "fpm_request.h"
105+
#include "fpm_status.h"
106+
#include "fpm_conf.h"
107+
#include "fpm_php.h"
108+
#include "fpm_log.h"
109+
#include "zlog.h"
110110

111111
#ifndef PHP_WIN32
112112
/* XXX this will need to change later when threaded fastcgi is implemented. shane */

sapi/fpm/fpm/fpm_php.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ int fpm_php_limit_extensions(char *path) /* {{{ */
253253
}
254254

255255

256-
zlog(ZLOG_NOTICE, "Access to the file '%s' has been denied (see security.limit_extensions)", path);
256+
zlog(ZLOG_NOTICE, "Access to the script '%s' has been denied (see security.limit_extensions)", path);
257257
return 1; /* extension not found: not allowed */
258258
}
259259
/* }}} */

sapi/fpm/fpm/fpm_php_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void fpm_php_trace(struct fpm_child_s *child) /* {{{ */
144144
slowlog = fopen(child->wp->config->slowlog, "a+");
145145

146146
if (!slowlog) {
147-
zlog(ZLOG_SYSERROR, "fopen(%s) failed", child->wp->config->slowlog);
147+
zlog(ZLOG_SYSERROR, "unable to open slowlog (%s)", child->wp->config->slowlog);
148148
goto done0;
149149
}
150150

sapi/fpm/fpm/fpm_process_ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static void fpm_pctl_exec() /* {{{ */
9999

100100
fpm_cleanups_run(FPM_CLEANUP_PARENT_EXEC);
101101
execvp(saved_argv[0], saved_argv);
102-
zlog(ZLOG_SYSERROR, "execvp() failed");
102+
zlog(ZLOG_SYSERROR, "failed to reload: execvp() failed");
103103
exit(1);
104104
}
105105
/* }}} */

0 commit comments

Comments
 (0)