~legolas/ubuntu/natty/php5/5.3.5

« back to all changes in this revision

Viewing changes to sapi/fpm/fpm/fpm_conf.c

  • Committer: Stas Verberkt
  • Date: 2011-02-01 09:27:15 UTC
  • Revision ID: legolas@legolasweb.nl-20110201092715-yq052iu2yl4i2eyg
Inserted PHP 5.3.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
static char *fpm_conf_set_rlimit_core(zval *value, void **config, intptr_t offset);
53
53
static char *fpm_conf_set_pm(zval *value, void **config, intptr_t offset);
54
54
 
55
 
struct fpm_global_config_s fpm_global_config = { 0, 0, 0, 1, NULL, NULL};
 
55
struct fpm_global_config_s fpm_global_config = { .daemonize = 1 };
56
56
static struct fpm_worker_pool_s *current_wp = NULL;
57
57
static int ini_recursion = 0;
58
58
static char *ini_filename = NULL;
59
59
static int ini_lineno = 0;
60
60
static char *ini_include = NULL;
61
61
 
 
62
#define GO(field) offsetof(struct fpm_global_config_s, field)
 
63
#define WPO(field) offsetof(struct fpm_worker_pool_config_s, field)
 
64
 
62
65
static struct ini_value_parser_s ini_fpm_global_options[] = {
63
 
        { "emergency_restart_threshold",        &fpm_conf_set_integer,  offsetof(struct fpm_global_config_s, emergency_restart_threshold) },
64
 
        { "emergency_restart_interval",         &fpm_conf_set_time,                     offsetof(struct fpm_global_config_s, emergency_restart_interval) },
65
 
        { "process_control_timeout",                    &fpm_conf_set_time,                     offsetof(struct fpm_global_config_s, process_control_timeout) },
66
 
        { "daemonize",                                                                          &fpm_conf_set_boolean,  offsetof(struct fpm_global_config_s, daemonize) },
67
 
        { "pid",                                                                                                        &fpm_conf_set_string,           offsetof(struct fpm_global_config_s, pid_file) },
68
 
        { "error_log",                                                                          &fpm_conf_set_string,           offsetof(struct fpm_global_config_s, error_log) },
 
66
        { "emergency_restart_threshold",        &fpm_conf_set_integer,  GO(emergency_restart_threshold) },
 
67
        { "emergency_restart_interval",         &fpm_conf_set_time,                     GO(emergency_restart_interval) },
 
68
        { "process_control_timeout",                    &fpm_conf_set_time,                     GO(process_control_timeout) },
 
69
        { "daemonize",                                                                          &fpm_conf_set_boolean,  GO(daemonize) },
 
70
        { "pid",                                                                                                        &fpm_conf_set_string,           GO(pid_file) },
 
71
        { "error_log",                                                                          &fpm_conf_set_string,           GO(error_log) },
69
72
        { "log_level",                                                                          &fpm_conf_set_log_level,        0 },
70
73
        { 0, 0, 0 }
71
74
};
72
75
 
73
76
static struct ini_value_parser_s ini_fpm_pool_options[] = {
74
 
        { "user", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, user) },
75
 
        { "group", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, group) },
76
 
        { "chroot", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, chroot) },
77
 
        { "chdir", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, chdir) },
78
 
        { "request_terminate_timeout", &fpm_conf_set_time, offsetof(struct fpm_worker_pool_config_s, request_terminate_timeout) },
79
 
        { "request_slowlog_timeout", &fpm_conf_set_time, offsetof(struct fpm_worker_pool_config_s, request_slowlog_timeout) },
80
 
        { "slowlog", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, slowlog) },
81
 
        { "rlimit_files", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, rlimit_files) },
82
 
        { "rlimit_core", &fpm_conf_set_rlimit_core, offsetof(struct fpm_worker_pool_config_s, rlimit_core) },
83
 
        { "catch_workers_output", &fpm_conf_set_boolean, offsetof(struct fpm_worker_pool_config_s, catch_workers_output) },
84
 
        { "listen", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, listen_address) },
85
 
        { "listen.owner", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, listen_owner) },
86
 
        { "listen.group", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, listen_group) },
87
 
        { "listen.mode", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, listen_mode) },
88
 
        { "listen.backlog", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, listen_backlog) },
89
 
        { "listen.allowed_clients", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, listen_allowed_clients) },
90
 
        { "pm", &fpm_conf_set_pm, offsetof(struct fpm_worker_pool_config_s, pm) },
91
 
        { "pm.max_requests", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, pm_max_requests) },
92
 
        { "pm.max_children", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, pm_max_children) },
93
 
        { "pm.start_servers", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, pm_start_servers) },
94
 
        { "pm.min_spare_servers", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, pm_min_spare_servers) },
95
 
        { "pm.max_spare_servers", &fpm_conf_set_integer, offsetof(struct fpm_worker_pool_config_s, pm_max_spare_servers) },
96
 
        { "pm.status_path", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, pm_status_path) },
97
 
        { "ping.path", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, ping_path) },
98
 
        { "ping.response", &fpm_conf_set_string, offsetof(struct fpm_worker_pool_config_s, ping_response) },
 
77
        { "prefix", &fpm_conf_set_string, WPO(prefix) },
 
78
        { "user", &fpm_conf_set_string, WPO(user) },
 
79
        { "group", &fpm_conf_set_string, WPO(group) },
 
80
        { "chroot", &fpm_conf_set_string, WPO(chroot) },
 
81
        { "chdir", &fpm_conf_set_string, WPO(chdir) },
 
82
        { "request_terminate_timeout", &fpm_conf_set_time, WPO(request_terminate_timeout) },
 
83
        { "request_slowlog_timeout", &fpm_conf_set_time, WPO(request_slowlog_timeout) },
 
84
        { "slowlog", &fpm_conf_set_string, WPO(slowlog) },
 
85
        { "rlimit_files", &fpm_conf_set_integer, WPO(rlimit_files) },
 
86
        { "rlimit_core", &fpm_conf_set_rlimit_core, WPO(rlimit_core) },
 
87
        { "catch_workers_output", &fpm_conf_set_boolean, WPO(catch_workers_output) },
 
88
        { "listen", &fpm_conf_set_string, WPO(listen_address) },
 
89
        { "listen.owner", &fpm_conf_set_string, WPO(listen_owner) },
 
90
        { "listen.group", &fpm_conf_set_string, WPO(listen_group) },
 
91
        { "listen.mode", &fpm_conf_set_string, WPO(listen_mode) },
 
92
        { "listen.backlog", &fpm_conf_set_integer, WPO(listen_backlog) },
 
93
        { "listen.allowed_clients", &fpm_conf_set_string, WPO(listen_allowed_clients) },
 
94
        { "pm", &fpm_conf_set_pm, WPO(pm) },
 
95
        { "pm.max_requests", &fpm_conf_set_integer, WPO(pm_max_requests) },
 
96
        { "pm.max_children", &fpm_conf_set_integer, WPO(pm_max_children) },
 
97
        { "pm.start_servers", &fpm_conf_set_integer, WPO(pm_start_servers) },
 
98
        { "pm.min_spare_servers", &fpm_conf_set_integer, WPO(pm_min_spare_servers) },
 
99
        { "pm.max_spare_servers", &fpm_conf_set_integer, WPO(pm_max_spare_servers) },
 
100
        { "pm.status_path", &fpm_conf_set_string, WPO(pm_status_path) },
 
101
        { "ping.path", &fpm_conf_set_string, WPO(ping_path) },
 
102
        { "ping.response", &fpm_conf_set_string, WPO(ping_response) },
99
103
        { 0, 0, 0 }
100
104
};
101
105
 
111
115
}
112
116
/* }}} */
113
117
 
 
118
static int fpm_conf_expand_pool_name(char **value) {
 
119
        char *token;
 
120
 
 
121
        if (!value || !*value) {
 
122
                return 0;
 
123
        }
 
124
 
 
125
        while ((token = strstr(*value, "$pool"))) {
 
126
                char *buf;
 
127
                char *p1 = *value;
 
128
                char *p2 = token + strlen("$pool");
 
129
                if (!current_wp || !current_wp->config  || !current_wp->config->name) {
 
130
                        return -1;
 
131
                }
 
132
                token[0] = '\0';
 
133
                spprintf(&buf, 0, "%s%s%s", p1, current_wp->config->name, p2);
 
134
                *value = strdup(buf);
 
135
                efree(buf);
 
136
        }
 
137
 
 
138
        return 0;
 
139
}
 
140
 
114
141
static char *fpm_conf_set_boolean(zval *value, void **config, intptr_t offset) /* {{{ */
115
142
{
116
143
        char *val = Z_STRVAL_P(value);
117
 
        long value_y = !strcasecmp(val, "yes") || !strcmp(val,  "1") || !strcasecmp(val, "on") || !strcasecmp(val, "true");
118
 
        long value_n = !strcasecmp(val, "no")  || !strcmp(val,  "0") || !strcasecmp(val, "off") || !strcasecmp(val, "false");
 
144
        long value_y = !strcasecmp(val, "1");
 
145
        long value_n = !strcasecmp(val, "");
119
146
 
120
147
        if (!value_y && !value_n) {
121
148
                return "invalid boolean value";
138
165
        if (!new) {
139
166
                return "fpm_conf_set_string(): strdup() failed";
140
167
        }
 
168
        if (fpm_conf_expand_pool_name(&new) == -1) {
 
169
                return "Can't use '$pool' when the pool is not defined";
 
170
        }
141
171
 
142
172
        *old = new;
143
173
        return NULL;
146
176
 
147
177
static char *fpm_conf_set_integer(zval *value, void **config, intptr_t offset) /* {{{ */
148
178
{
149
 
        int i;
150
179
        char *val = Z_STRVAL_P(value);
 
180
        char *p;
151
181
 
152
 
        for (i=0; i<strlen(val); i++) {
153
 
                if ( i == 0 && val[i] == '-' ) continue;
154
 
                if (val[i] < '0' || val[i] > '9') {
155
 
                        return("is not a valid number (greater or equal than zero");
 
182
        for(p=val; *p; p++) {
 
183
                if ( p == val && *p == '-' ) continue;
 
184
                if (*p < '0' || *p > '9') {
 
185
                        return "is not a valid number (greater or equal than zero)";
156
186
                }
157
187
        }
158
188
        * (int *) ((char *) *config + offset) = atoi(val);
159
 
        return(NULL);
 
189
        return NULL;
160
190
}
161
191
/* }}} */
162
192
 
204
234
{
205
235
        char *val = Z_STRVAL_P(value);
206
236
 
207
 
        if (!strcmp(val, "debug")) {
 
237
        if (!strcasecmp(val, "debug")) {
208
238
                fpm_globals.log_level = ZLOG_DEBUG;
209
239
        } else if (!strcasecmp(val, "notice")) {
210
240
                fpm_globals.log_level = ZLOG_NOTICE;
227
257
        char *val = Z_STRVAL_P(value);
228
258
        struct fpm_worker_pool_config_s *c = *config;
229
259
 
230
 
        if (!strcmp(val, "unlimited")) {
 
260
        if (!strcasecmp(val, "unlimited")) {
231
261
                c->rlimit_core = -1;
232
262
        } else {
233
263
                int int_value;
255
285
{
256
286
        char *val = Z_STRVAL_P(value);
257
287
        struct fpm_worker_pool_config_s  *c = *config;
258
 
        if (!strcmp(val, "static")) {
 
288
        if (!strcasecmp(val, "static")) {
259
289
                c->pm = PM_STYLE_STATIC;
260
 
        } else if (!strcmp(val, "dynamic")) {
 
290
        } else if (!strcasecmp(val, "dynamic")) {
261
291
                c->pm = PM_STYLE_DYNAMIC;
262
292
        } else {
263
293
                return "invalid process manager (static or dynamic)";
288
318
 
289
319
        if (convert_to_bool) {
290
320
                char *err = fpm_conf_set_boolean(value, &subconf, 0);
291
 
                if (err) return(err);
 
321
                if (err) return err;
292
322
                kv->value = strdup(b ? "On" : "Off");
293
323
        } else {
294
324
                kv->value = strdup(Z_STRVAL_P(value));
 
325
                if (fpm_conf_expand_pool_name(&kv->value) == -1) {
 
326
                        return "Can't use '$pool' when the pool is not defined";
 
327
                }
295
328
        }
296
329
 
297
330
        if (!kv->value) {
322
355
        }
323
356
 
324
357
        memset(wp->config, 0, sizeof(struct fpm_worker_pool_config_s));
325
 
        wp->config->listen_backlog = -1;
 
358
        wp->config->listen_backlog = FPM_BACKLOG_DEFAULT;
326
359
 
327
360
        if (!fpm_worker_all_pools) {
328
361
                fpm_worker_all_pools = wp;
378
411
        free(wpc->chroot);
379
412
        free(wpc->chdir);
380
413
        free(wpc->slowlog);
 
414
        free(wpc->prefix);
381
415
 
382
416
        return 0;
383
417
}
384
418
/* }}} */
385
419
 
386
 
static int fpm_evaluate_full_path(char **path) /* {{{ */
 
420
static int fpm_evaluate_full_path(char **path, struct fpm_worker_pool_s *wp, char *default_prefix, int expand) /* {{{ */
387
421
{
388
 
        if (**path != '/') {
389
 
                char *full_path;
390
 
 
391
 
                full_path = malloc(sizeof(PHP_PREFIX) + strlen(*path) + 1);
392
 
 
393
 
                if (!full_path) { 
394
 
                        return -1;
 
422
        char *prefix = NULL;
 
423
        char *full_path;
 
424
 
 
425
        if (!path || !*path || **path == '/') {
 
426
                return 0;
 
427
        }
 
428
 
 
429
        if (wp && wp->config) {
 
430
                prefix = wp->config->prefix;
 
431
        }
 
432
 
 
433
        /* if the wp prefix is not set */
 
434
        if (prefix == NULL) {
 
435
                prefix = fpm_globals.prefix;
 
436
        }
 
437
 
 
438
        /* if the global prefix is not set */
 
439
        if (prefix == NULL) {
 
440
                prefix = default_prefix ? default_prefix : PHP_PREFIX;
 
441
        }
 
442
 
 
443
        if (expand) {
 
444
                char *tmp;
 
445
                tmp = strstr(*path, "$prefix");
 
446
                if (tmp != NULL) {
 
447
 
 
448
                        if (tmp != *path) {
 
449
                                zlog(ZLOG_ERROR, "'$prefix' must be use at the begining of the value");
 
450
                                return -1;
 
451
                        }
 
452
 
 
453
                        if (strlen(*path) > strlen("$prefix")) {
 
454
                                free(*path);
 
455
                                tmp = strdup((*path) + strlen("$prefix"));
 
456
                                *path = tmp;
 
457
                        } else {
 
458
                                free(*path);
 
459
                                *path = NULL;
 
460
                        }
395
461
                }
 
462
        }
396
463
 
397
 
                sprintf(full_path, "%s/%s", PHP_PREFIX, *path);
 
464
        if (*path) {
 
465
                spprintf(&full_path, 0, "%s/%s", prefix, *path);
398
466
                free(*path);
399
 
                *path = full_path;
 
467
                *path = strdup(full_path);
 
468
                efree(full_path);
 
469
        } else {
 
470
                *path = strdup(prefix);
400
471
        }
401
472
 
 
473
        if (**path != '/' && wp != NULL && wp->config) {
 
474
                return fpm_evaluate_full_path(path, NULL, default_prefix, expand);
 
475
        }
402
476
        return 0;
403
477
}
404
478
/* }}} */
408
482
        struct fpm_worker_pool_s *wp;
409
483
 
410
484
        if (!fpm_worker_all_pools) {
411
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "at least one pool section must be specified in config file");
 
485
                zlog(ZLOG_ERROR, "at least one pool section must be specified in config file");
412
486
                return -1;
413
487
        }
414
488
 
415
489
        for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
416
490
 
 
491
                if (wp->config->prefix && *wp->config->prefix) {
 
492
                        fpm_evaluate_full_path(&wp->config->prefix, NULL, NULL, 0);
 
493
 
 
494
                        if (!fpm_conf_is_dir(wp->config->prefix)) {
 
495
                                zlog(ZLOG_ERROR, "[pool %s] the prefix '%s' does not exist or is not a directory", wp->config->name, wp->config->prefix);
 
496
                                return -1;
 
497
                        }
 
498
                }
 
499
 
417
500
                if (wp->config->listen_address && *wp->config->listen_address) {
418
501
                        wp->listen_address_domain = fpm_sockets_domain_from_address(wp->config->listen_address);
419
502
 
420
503
                        if (wp->listen_address_domain == FPM_AF_UNIX && *wp->config->listen_address != '/') {
421
 
                                fpm_evaluate_full_path(&wp->config->listen_address);
 
504
                                fpm_evaluate_full_path(&wp->config->listen_address, wp, NULL, 0);
422
505
                        }
423
506
                } else {
424
 
                        zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] no listen address have been defined!", wp->config->name);
 
507
                        zlog(ZLOG_ALERT, "[pool %s] no listen address have been defined!", wp->config->name);
425
508
                        return -1;
426
509
                }
427
510
 
428
511
                if (!wp->config->user) {
429
 
                        zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] user has not been defined", wp->config->name);
 
512
                        zlog(ZLOG_ALERT, "[pool %s] user has not been defined", wp->config->name);
430
513
                        return -1;
431
514
                }
432
515
 
433
516
                if (wp->config->pm != PM_STYLE_STATIC && wp->config->pm != PM_STYLE_DYNAMIC) {
434
 
                        zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] the process manager is missing (static or dynamic)", wp->config->name);
 
517
                        zlog(ZLOG_ALERT, "[pool %s] the process manager is missing (static or dynamic)", wp->config->name);
435
518
                        return -1;
436
519
                }
437
520
 
438
521
                if (wp->config->pm_max_children < 1) {
439
 
                        zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] pm.max_children must be a positive value", wp->config->name);
 
522
                        zlog(ZLOG_ALERT, "[pool %s] pm.max_children must be a positive value", wp->config->name);
440
523
                        return -1;
441
524
                }
442
525
 
444
527
                        struct fpm_worker_pool_config_s *config = wp->config;
445
528
 
446
529
                        if (config->pm_min_spare_servers <= 0) {
447
 
                                zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) must be a positive value", wp->config->name, config->pm_min_spare_servers);
 
530
                                zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) must be a positive value", wp->config->name, config->pm_min_spare_servers);
448
531
                                return -1;
449
532
                        }
450
533
 
451
534
                        if (config->pm_max_spare_servers <= 0) {
452
 
                                zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must be a positive value", wp->config->name, config->pm_max_spare_servers);
 
535
                                zlog(ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must be a positive value", wp->config->name, config->pm_max_spare_servers);
453
536
                                return -1;
454
537
                        }
455
538
 
456
539
                        if (config->pm_min_spare_servers > config->pm_max_children ||
457
540
                                        config->pm_max_spare_servers > config->pm_max_children) {
458
 
                                zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) and pm.max_spare_servers(%d) cannot be greater than pm.max_children(%d)",
 
541
                                zlog(ZLOG_ALERT, "[pool %s] pm.min_spare_servers(%d) and pm.max_spare_servers(%d) cannot be greater than pm.max_children(%d)",
459
542
                                                wp->config->name, config->pm_min_spare_servers, config->pm_max_spare_servers, config->pm_max_children);
460
543
                                return -1;
461
544
                        }
462
545
 
463
546
                        if (config->pm_max_spare_servers < config->pm_min_spare_servers) {
464
 
                                zlog(ZLOG_STUFF, ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must not be less than pm.min_spare_servers(%d)", wp->config->name, config->pm_max_spare_servers, config->pm_min_spare_servers);
 
547
                                zlog(ZLOG_ALERT, "[pool %s] pm.max_spare_servers(%d) must not be less than pm.min_spare_servers(%d)", wp->config->name, config->pm_max_spare_servers, config->pm_min_spare_servers);
465
548
                                return -1;
466
549
                        }
467
550
 
468
551
                        if (config->pm_start_servers <= 0) {
469
552
                                config->pm_start_servers = config->pm_min_spare_servers + ((config->pm_max_spare_servers - config->pm_min_spare_servers) / 2);
470
 
                                zlog(ZLOG_STUFF, ZLOG_WARNING, "[pool %s] pm.start_servers is not set. It's been set to %d.", wp->config->name, config->pm_start_servers);
 
553
                                zlog(ZLOG_WARNING, "[pool %s] pm.start_servers is not set. It's been set to %d.", wp->config->name, config->pm_start_servers);
471
554
                        } else if (config->pm_start_servers < config->pm_min_spare_servers || config->pm_start_servers > config->pm_max_spare_servers) {
472
 
                                zlog(ZLOG_STUFF, 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);
 
555
                                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);
473
556
                                return -1;
474
557
                        }
475
558
 
476
559
                }
477
560
 
 
561
                if (wp->config->slowlog && *wp->config->slowlog) {
 
562
                        fpm_evaluate_full_path(&wp->config->slowlog, wp, NULL, 0);
 
563
                }
478
564
 
479
565
                if (wp->config->request_slowlog_timeout) {
480
566
#if HAVE_FPM_TRACE
481
567
                        if (! (wp->config->slowlog && *wp->config->slowlog)) {
482
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_timeout'", wp->config->name);
 
568
                                zlog(ZLOG_ERROR, "[pool %s] 'slowlog' must be specified for use with 'request_slowlog_timeout'", wp->config->name);
483
569
                                return -1;
484
570
                        }
485
571
#else
486
572
                        static int warned = 0;
487
573
 
488
574
                        if (!warned) {
489
 
                                zlog(ZLOG_STUFF, ZLOG_WARNING, "[pool %s] 'request_slowlog_timeout' is not supported on your system",   wp->config->name);
 
575
                                zlog(ZLOG_WARNING, "[pool %s] 'request_slowlog_timeout' is not supported on your system",       wp->config->name);
490
576
                                warned = 1;
491
577
                        }
492
578
 
493
579
                        wp->config->request_slowlog_timeout = 0;
494
580
#endif
495
 
                }
496
 
 
497
 
                if (wp->config->request_slowlog_timeout && wp->config->slowlog && *wp->config->slowlog) {
498
 
                        int fd;
499
 
 
500
 
                        fpm_evaluate_full_path(&wp->config->slowlog);
501
 
 
502
 
                        if (wp->config->request_slowlog_timeout) {
 
581
 
 
582
                        if (wp->config->slowlog && *wp->config->slowlog) {
 
583
                                int fd;
 
584
 
503
585
                                fd = open(wp->config->slowlog, O_WRONLY | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);
504
586
 
505
587
                                if (0 > fd) {
506
 
                                        zlog(ZLOG_STUFF, ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog);
 
588
                                        zlog(ZLOG_SYSERROR, "open(%s) failed", wp->config->slowlog);
507
589
                                        return -1;
508
590
                                }
509
591
                                close(fd);
515
597
                        int i;
516
598
 
517
599
                        if (*ping != '/') {
518
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the ping path '%s' must start with a '/'", wp->config->name, ping);
 
600
                                zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' must start with a '/'", wp->config->name, ping);
519
601
                                return -1;
520
602
                        }
521
603
 
522
604
                        if (strlen(ping) < 2) {
523
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the ping path '%s' is not long enough", wp->config->name, ping);
 
605
                                zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' is not long enough", wp->config->name, ping);
524
606
                                return -1;
525
607
                        }
526
608
 
527
609
                        for (i=0; i<strlen(ping); i++) {
528
610
                                if (!isalnum(ping[i]) && ping[i] != '/' && ping[i] != '-' && ping[i] != '_' && ping[i] != '.') {
529
 
                                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the ping path '%s' must containt only the following characters '[alphanum]/_-.'", wp->config->name, ping);
 
611
                                        zlog(ZLOG_ERROR, "[pool %s] the ping path '%s' must containt only the following characters '[alphanum]/_-.'", wp->config->name, ping);
530
612
                                        return -1;
531
613
                                }
532
614
                        }
535
617
                                wp->config->ping_response = strdup("pong");
536
618
                        } else {
537
619
                                if (strlen(wp->config->ping_response) < 1) {
538
 
                                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the ping response page '%s' is not long enough", wp->config->name, wp->config->ping_response);
 
620
                                        zlog(ZLOG_ERROR, "[pool %s] the ping response page '%s' is not long enough", wp->config->name, wp->config->ping_response);
539
621
                                        return -1;
540
622
                                }
541
623
                        }
552
634
                        /* struct fpm_status_s fpm_status; */
553
635
 
554
636
                        if (*status != '/') {
555
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the status path '%s' must start with a '/'", wp->config->name, status);
 
637
                                zlog(ZLOG_ERROR, "[pool %s] the status path '%s' must start with a '/'", wp->config->name, status);
556
638
                                return -1;
557
639
                        }
558
640
 
559
641
                        if (strlen(status) < 2) {
560
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the status path '%s' is not long enough", wp->config->name, status);
 
642
                                zlog(ZLOG_ERROR, "[pool %s] the status path '%s' is not long enough", wp->config->name, status);
561
643
                                return -1;
562
644
                        }
563
645
 
564
646
                        for (i=0; i<strlen(status); i++) {
565
647
                                if (!isalnum(status[i]) && status[i] != '/' && status[i] != '-' && status[i] != '_' && status[i] != '.') {
566
 
                                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the status path '%s' must contain only the following characters '[alphanum]/_-.'", wp->config->name, status);
 
648
                                        zlog(ZLOG_ERROR, "[pool %s] the status path '%s' must contain only the following characters '[alphanum]/_-.'", wp->config->name, status);
567
649
                                        return -1;
568
650
                                }
569
651
                        }
570
652
                        wp->shm_status = fpm_shm_alloc(sizeof(struct fpm_status_s));
571
653
                        if (!wp->shm_status) {
572
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] unable to allocate shared memory for status page '%s'", wp->config->name, status);
 
654
                                zlog(ZLOG_ERROR, "[pool %s] unable to allocate shared memory for status page '%s'", wp->config->name, status);
573
655
                                return -1;
574
656
                        }
575
657
                        fpm_status_update_accepted_conn(wp->shm_status, 0);
576
 
                        fpm_status_update_activity(wp->shm_status, -1, -1, -1, 1);
 
658
                        fpm_status_update_activity(wp->shm_status, -1, -1, -1, 0, -1, 1);
 
659
                        fpm_status_update_max_children_reached(wp->shm_status, 0);
577
660
                        fpm_status_set_pm(wp->shm_status, wp->config->pm);
578
661
                        /* memset(&fpm_status.last_update, 0, sizeof(fpm_status.last_update)); */
579
662
                }
580
663
 
581
664
                if (wp->config->chroot && *wp->config->chroot) {
 
665
 
 
666
                        fpm_evaluate_full_path(&wp->config->chroot, wp, NULL, 1);
 
667
 
582
668
                        if (*wp->config->chroot != '/') {
583
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chroot path '%s' must start with a '/'", wp->config->name, wp->config->chroot);
 
669
                                zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' must start with a '/'", wp->config->name, wp->config->chroot);
584
670
                                return -1;
585
671
                        }
586
672
                        if (!fpm_conf_is_dir(wp->config->chroot)) {
587
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chroot path '%s' does not exist or is not a directory", wp->config->name, wp->config->chroot);
 
673
                                zlog(ZLOG_ERROR, "[pool %s] the chroot path '%s' does not exist or is not a directory", wp->config->name, wp->config->chroot);
588
674
                                return -1;
589
675
                        }
590
676
                }
591
677
 
592
678
                if (wp->config->chdir && *wp->config->chdir) {
 
679
 
 
680
                        fpm_evaluate_full_path(&wp->config->chdir, wp, NULL, 0);
 
681
 
593
682
                        if (*wp->config->chdir != '/') {
594
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' must start with a '/'", wp->config->name, wp->config->chdir);
 
683
                                zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' must start with a '/'", wp->config->name, wp->config->chdir);
595
684
                                return -1;
596
685
                        }
597
686
 
598
687
                        if (wp->config->chroot) {
599
688
                                char *buf;
600
 
                                size_t len;
601
 
 
602
 
                                len = strlen(wp->config->chroot) + strlen(wp->config->chdir) + 1;
603
 
                                buf = malloc(sizeof(char) * len);
604
 
                                if (!buf) {
605
 
                                        zlog(ZLOG_STUFF, ZLOG_SYSERROR, "[pool %s] malloc() failed", wp->config->name);
606
 
                                        return -1;
607
 
                                }
608
 
                                snprintf(buf, len, "%s%s", wp->config->chroot, wp->config->chdir);
 
689
 
 
690
                                spprintf(&buf, 0, "%s/%s", wp->config->chroot, wp->config->chdir);
 
691
 
609
692
                                if (!fpm_conf_is_dir(buf)) {
610
 
                                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' within the chroot path '%s' ('%s') does not exist or is not a directory", wp->config->name, wp->config->chdir, wp->config->chroot, buf);
611
 
                                        free(buf);
 
693
                                        zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' within the chroot path '%s' ('%s') does not exist or is not a directory", wp->config->name, wp->config->chdir, wp->config->chroot, buf);
 
694
                                        efree(buf);
612
695
                                        return -1;
613
696
                                }
614
 
                                free(buf);
 
697
 
 
698
                                efree(buf);
615
699
                        } else {
616
700
                                if (!fpm_conf_is_dir(wp->config->chdir)) {
617
 
                                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[pool %s] the chdir path '%s' does not exist or is not a directory", wp->config->name, wp->config->chdir);
 
701
                                        zlog(ZLOG_ERROR, "[pool %s] the chdir path '%s' does not exist or is not a directory", wp->config->name, wp->config->chdir);
618
702
                                        return -1;
619
703
                                }
620
704
                        }
621
705
                }
 
706
                if (!wp->config->chroot) {
 
707
                        struct key_value_s *kv;
 
708
                        char *options[] = FPM_PHP_INI_TO_EXPAND;
 
709
                        char **p;
 
710
 
 
711
                        for (kv = wp->config->php_values; kv; kv = kv->next) {
 
712
                                for (p=options; *p; p++) {
 
713
                                        if (!strcasecmp(kv->key, *p)) {
 
714
                                                fpm_evaluate_full_path(&kv->value, wp, NULL, 0);
 
715
                                        }
 
716
                                }
 
717
                        }
 
718
                        for (kv = wp->config->php_admin_values; kv; kv = kv->next) {
 
719
                                for (p=options; *p; p++) {
 
720
                                        if (!strcasecmp(kv->key, *p)) {
 
721
                                                fpm_evaluate_full_path(&kv->value, wp, NULL, 0);
 
722
                                        }
 
723
                                }
 
724
                        }
 
725
                }
622
726
        }
623
727
        return 0;
624
728
}
628
732
{
629
733
        if (fpm_global_config.pid_file) {
630
734
                if (0 > unlink(fpm_global_config.pid_file)) {
631
 
                        zlog(ZLOG_STUFF, ZLOG_SYSERROR, "unlink(\"%s\") failed", fpm_global_config.pid_file);
 
735
                        zlog(ZLOG_SYSERROR, "unlink(\"%s\") failed", fpm_global_config.pid_file);
632
736
                        return -1;
633
737
                }
634
738
        }
648
752
                fd = creat(fpm_global_config.pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
649
753
 
650
754
                if (fd < 0) {
651
 
                        zlog(ZLOG_STUFF, ZLOG_SYSERROR, "creat(\"%s\") failed", fpm_global_config.pid_file);
 
755
                        zlog(ZLOG_SYSERROR, "creat(\"%s\") failed", fpm_global_config.pid_file);
652
756
                        return -1;
653
757
                }
654
758
 
655
759
                len = sprintf(buf, "%d", (int) fpm_globals.parent_pid);
656
760
 
657
761
                if (len != write(fd, buf, len)) {
658
 
                        zlog(ZLOG_STUFF, ZLOG_SYSERROR, "write() failed");
 
762
                        zlog(ZLOG_SYSERROR, "write() failed");
659
763
                        return -1;
660
764
                }
661
765
                close(fd);
667
771
static int fpm_conf_post_process() /* {{{ */
668
772
{
669
773
        if (fpm_global_config.pid_file) {
670
 
                fpm_evaluate_full_path(&fpm_global_config.pid_file);
 
774
                fpm_evaluate_full_path(&fpm_global_config.pid_file, NULL, PHP_LOCALSTATEDIR, 0);
671
775
        }
672
776
 
673
777
        if (!fpm_global_config.error_log) {
674
 
                char *tmp_log_path;
675
 
 
676
 
                spprintf(&tmp_log_path, 0, "%s/log/php-fpm.log", PHP_LOCALSTATEDIR);
677
 
                fpm_global_config.error_log = strdup(tmp_log_path);
678
 
                efree(tmp_log_path);
 
778
                fpm_global_config.error_log = strdup("log/php-fpm.log");
679
779
        }
680
780
 
681
 
        fpm_evaluate_full_path(&fpm_global_config.error_log);
 
781
        fpm_evaluate_full_path(&fpm_global_config.error_log, NULL, PHP_LOCALSTATEDIR, 0);
682
782
 
683
783
        if (0 > fpm_stdio_open_error_log(0)) {
684
784
                return -1;
694
794
        free(fpm_global_config.error_log);
695
795
        fpm_global_config.pid_file = 0;
696
796
        fpm_global_config.error_log = 0;
 
797
        free(fpm_globals.config);
697
798
}
698
799
/* }}} */
699
800
 
714
815
                if ((i = glob(inc, GLOB_ERR | GLOB_MARK | GLOB_NOSORT, NULL, &g)) != 0) {
715
816
#ifdef GLOB_NOMATCH
716
817
                        if (i == GLOB_NOMATCH) {
717
 
                                zlog(ZLOG_STUFF, ZLOG_WARNING, "Nothing matches the include pattern '%s' from %s at line %d.", inc, filename, ini_lineno);
 
818
                                zlog(ZLOG_WARNING, "Nothing matches the include pattern '%s' from %s at line %d.", inc, filename, ini_lineno);
 
819
                                efree(filename);
718
820
                                return;
719
821
                        } 
720
822
#endif /* GLOB_NOMATCH */
721
 
                        zlog(ZLOG_STUFF, ZLOG_ERROR, "Unable to globalize '%s' (ret=%d) from %s at line %d.", inc, i, filename, ini_lineno);
 
823
                        zlog(ZLOG_ERROR, "Unable to globalize '%s' (ret=%d) from %s at line %d.", inc, i, filename, ini_lineno);
722
824
                        *error = 1;
 
825
                        efree(filename);
723
826
                        return;
724
827
                }
725
828
 
728
831
                        if (len < 1) continue;
729
832
                        if (g.gl_pathv[i][len - 1] == '/') continue; /* don't parse directories */
730
833
                        if (0 > fpm_conf_load_ini_file(g.gl_pathv[i] TSRMLS_CC)) {
731
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno);
 
834
                                zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", g.gl_pathv[i], filename, ini_lineno);
732
835
                                *error = 1;
 
836
                                efree(filename);
733
837
                                return;
734
838
                        }
735
839
                }
737
841
        }
738
842
#else /* HAVE_GLOB */
739
843
        if (0 > fpm_conf_load_ini_file(inc TSRMLS_CC)) {
740
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "Unable to include %s from %s at line %d", inc, filename, ini_lineno);
 
844
                zlog(ZLOG_ERROR, "Unable to include %s from %s at line %d", inc, filename, ini_lineno);
741
845
                *error = 1;
 
846
                efree(filename);
742
847
                return;
743
848
        }
744
849
#endif /* HAVE_GLOB */
 
850
 
 
851
        efree(filename);
745
852
}
746
853
/* }}} */
747
854
 
770
877
        /* it's a new pool */
771
878
        config = (struct fpm_worker_pool_config_s *)fpm_worker_pool_config_alloc();
772
879
        if (!current_wp || !config) {
773
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] Unable to alloc a new WorkerPool for worker '%s'", ini_filename, ini_lineno, Z_STRVAL_P(section));
 
880
                zlog(ZLOG_ERROR, "[%s:%d] Unable to alloc a new WorkerPool for worker '%s'", ini_filename, ini_lineno, Z_STRVAL_P(section));
774
881
                *error = 1;
775
882
                return;
776
883
        }
777
884
        config->name = strdup(Z_STRVAL_P(section));
778
885
        if (!config->name) {
779
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] Unable to alloc memory for configuration name for worker '%s'", ini_filename, ini_lineno, Z_STRVAL_P(section));
 
886
                zlog(ZLOG_ERROR, "[%s:%d] Unable to alloc memory for configuration name for worker '%s'", ini_filename, ini_lineno, Z_STRVAL_P(section));
780
887
                *error = 1;
781
888
                return;
782
889
        }
790
897
 
791
898
        int *error = (int *)arg;
792
899
        if (!value) {
793
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] value is NULL for a ZEND_INI_PARSER_ENTRY", ini_filename, ini_lineno);
 
900
                zlog(ZLOG_ERROR, "[%s:%d] value is NULL for a ZEND_INI_PARSER_ENTRY", ini_filename, ini_lineno);
794
901
                *error = 1;
795
902
                return;
796
903
        }
797
904
 
798
905
        if (!strcmp(Z_STRVAL_P(name), "include")) {
799
906
                if (ini_include) {
800
 
                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] two includes at the same time !", ini_filename, ini_lineno);
 
907
                        zlog(ZLOG_ERROR, "[%s:%d] two includes at the same time !", ini_filename, ini_lineno);
801
908
                        *error = 1;
802
909
                        return;
803
910
                }
817
924
                if (!strcasecmp(parser->name, Z_STRVAL_P(name))) {
818
925
                        char *ret;
819
926
                        if (!parser->parser) {
820
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] the parser for entry '%s' is not defined", ini_filename, ini_lineno, parser->name);
 
927
                                zlog(ZLOG_ERROR, "[%s:%d] the parser for entry '%s' is not defined", ini_filename, ini_lineno, parser->name);
821
928
                                *error = 1;
822
929
                                return;
823
930
                        }
824
931
 
825
932
                        ret = parser->parser(value, &config, parser->offset);
826
933
                        if (ret) {
827
 
                                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] unable to parse value for entry '%s': %s", ini_filename, ini_lineno, parser->name, ret);
 
934
                                zlog(ZLOG_ERROR, "[%s:%d] unable to parse value for entry '%s': %s", ini_filename, ini_lineno, parser->name, ret);
828
935
                                *error = 1;
829
936
                                return;
830
937
                        }
835
942
        }
836
943
 
837
944
        /* nothing has been found if we got here */
838
 
        zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] unknown entry '%s'", ini_filename, ini_lineno, Z_STRVAL_P(name));
 
945
        zlog(ZLOG_ERROR, "[%s:%d] unknown entry '%s'", ini_filename, ini_lineno, Z_STRVAL_P(name));
839
946
        *error = 1;
840
947
}
841
948
/* }}} */
846
953
        char *err = NULL;
847
954
        void *config;
848
955
 
849
 
        if (!Z_STRVAL_P(key) || !Z_STRVAL_P(value) || !*Z_STRVAL_P(key) || !*Z_STRVAL_P(value)) {
850
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] Mispell array ?", ini_filename, ini_lineno);
 
956
        if (!Z_STRVAL_P(key) || !Z_STRVAL_P(value) || !*Z_STRVAL_P(key)) {
 
957
                zlog(ZLOG_ERROR, "[%s:%d] Misspelled  array ?", ini_filename, ini_lineno);
851
958
                *error = 1;
852
959
                return;
853
960
        }
854
961
        if (!current_wp || !current_wp->config) {
855
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] Array are not allowed in the global section", ini_filename, ini_lineno);
 
962
                zlog(ZLOG_ERROR, "[%s:%d] Array are not allowed in the global section", ini_filename, ini_lineno);
856
963
                *error = 1;
857
964
                return;
858
965
        }
859
966
 
860
967
        if (!strcmp("env", Z_STRVAL_P(name))) {
861
 
                config = (char *)current_wp->config + offsetof(struct fpm_worker_pool_config_s, env);
 
968
                if (!*Z_STRVAL_P(value)) {
 
969
                        zlog(ZLOG_ERROR, "[%s:%d] empty value", ini_filename, ini_lineno);
 
970
                        *error = 1;
 
971
                        return;
 
972
                }
 
973
                config = (char *)current_wp->config + WPO(env);
862
974
                err = fpm_conf_set_array(key, value, &config, 0);
863
975
 
864
976
        } else if (!strcmp("php_value", Z_STRVAL_P(name))) {
865
 
                config = (char *)current_wp->config + offsetof(struct fpm_worker_pool_config_s, php_values);
 
977
                if (!*Z_STRVAL_P(value)) {
 
978
                        zlog(ZLOG_ERROR, "[%s:%d] empty value", ini_filename, ini_lineno);
 
979
                        *error = 1;
 
980
                        return;
 
981
                }
 
982
                config = (char *)current_wp->config + WPO(php_values);
866
983
                err = fpm_conf_set_array(key, value, &config, 0);
867
984
 
868
985
        } else if (!strcmp("php_admin_value", Z_STRVAL_P(name))) {
869
 
                config = (char *)current_wp->config + offsetof(struct fpm_worker_pool_config_s, php_admin_values);
 
986
                if (!*Z_STRVAL_P(value)) {
 
987
                        zlog(ZLOG_ERROR, "[%s:%d] empty value", ini_filename, ini_lineno);
 
988
                        *error = 1;
 
989
                        return;
 
990
                }
 
991
                config = (char *)current_wp->config + WPO(php_admin_values);
870
992
                err = fpm_conf_set_array(key, value, &config, 0);
871
993
 
872
994
        } else if (!strcmp("php_flag", Z_STRVAL_P(name))) {
873
 
                config = (char *)current_wp->config + offsetof(struct fpm_worker_pool_config_s, php_values);
 
995
                config = (char *)current_wp->config + WPO(php_values);
874
996
                err = fpm_conf_set_array(key, value, &config, 1);
875
997
 
876
998
        } else if (!strcmp("php_admin_flag", Z_STRVAL_P(name))) {
877
 
                config = (char *)current_wp->config + offsetof(struct fpm_worker_pool_config_s, php_admin_values);
 
999
                config = (char *)current_wp->config + WPO(php_admin_values);
878
1000
                err = fpm_conf_set_array(key, value, &config, 1);
879
1001
 
880
1002
        } else {
881
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] unknown directive '%s'", ini_filename, ini_lineno, Z_STRVAL_P(name));
 
1003
                zlog(ZLOG_ERROR, "[%s:%d] unknown directive '%s'", ini_filename, ini_lineno, Z_STRVAL_P(name));
882
1004
                *error = 1;
883
1005
                return;
884
1006
        }
885
1007
 
886
1008
        if (err) {
887
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] error while parsing '%s[%s]' : %s", ini_filename, ini_lineno, Z_STRVAL_P(name), Z_STRVAL_P(key), err);
 
1009
                zlog(ZLOG_ERROR, "[%s:%d] error while parsing '%s[%s]' : %s", ini_filename, ini_lineno, Z_STRVAL_P(name), Z_STRVAL_P(key), err);
888
1010
                *error = 1;
889
1011
                return;
890
1012
        }
910
1032
                        fpm_conf_ini_parser_array(arg1, arg3, arg2, error TSRMLS_CC);
911
1033
                        break;;
912
1034
                default:
913
 
                        zlog(ZLOG_STUFF, ZLOG_ERROR, "[%s:%d] Unknown INI syntax", ini_filename, ini_lineno);
 
1035
                        zlog(ZLOG_ERROR, "[%s:%d] Unknown INI syntax", ini_filename, ini_lineno);
914
1036
                        *error = 1;
915
1037
                        break;;
916
1038
        }
928
1050
        int ret = 1;
929
1051
 
930
1052
        if (!filename || !filename[0]) {
931
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "Configuration file is empty");
 
1053
                zlog(ZLOG_ERROR, "Configuration file is empty");
932
1054
                return -1;
933
1055
        }
934
1056
 
935
1057
        fd = open(filename, O_RDONLY, 0);
936
1058
        if (fd < 0) {
937
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "Unable to open file '%s', errno=%d", filename, errno);
 
1059
                zlog(ZLOG_ERROR, "Unable to open file '%s', errno=%d", filename, errno);
938
1060
                return -1;
939
1061
        }
940
1062
 
941
1063
        if (ini_recursion++ > 4) {
942
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "You can include more than 5 files recusively");
 
1064
                zlog(ZLOG_ERROR, "You can include more than 5 files recusively");
943
1065
                return -1;
944
1066
        }
945
1067
 
953
1075
                buf[n++] = '\n';
954
1076
                ini_lineno++;
955
1077
                ini_filename = filename;
956
 
                tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_RAW, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC);
 
1078
                tmp = zend_parse_ini_string(buf, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t)fpm_conf_ini_parser, &error TSRMLS_CC);
957
1079
                ini_filename = filename;
958
1080
                if (error || tmp == FAILURE) {
959
1081
                        if (ini_include) free(ini_include);
964
1086
                if (ini_include) {
965
1087
                        char *tmp = ini_include;
966
1088
                        ini_include = NULL;
967
 
                        fpm_evaluate_full_path(&tmp);
 
1089
                        fpm_evaluate_full_path(&tmp, NULL, NULL, 0);
968
1090
                        fpm_conf_ini_parser_include(tmp, &error TSRMLS_CC);
969
1091
                        if (error) {
970
1092
                                free(tmp);
983
1105
}
984
1106
/* }}} */
985
1107
 
986
 
int fpm_conf_init_main() /* {{{ */
987
 
{
988
 
        char *filename = fpm_globals.config;
989
 
        int free = 0;
 
1108
static void fpm_conf_dump() /* {{{ */
 
1109
{
 
1110
        struct fpm_worker_pool_s *wp;
 
1111
 
 
1112
        zlog(ZLOG_NOTICE, "[General]");
 
1113
        zlog(ZLOG_NOTICE, "\tpid = %s", STR2STR(fpm_global_config.pid_file));
 
1114
        zlog(ZLOG_NOTICE, "\tdaemonize = %s", BOOL2STR(fpm_global_config.daemonize));
 
1115
        zlog(ZLOG_NOTICE, "\terror_log = %s", STR2STR(fpm_global_config.error_log));
 
1116
        zlog(ZLOG_NOTICE, "\tlog_level = %s", zlog_get_level_name());
 
1117
        zlog(ZLOG_NOTICE, "\tprocess_control_timeout = %ds", fpm_global_config.process_control_timeout);
 
1118
        zlog(ZLOG_NOTICE, "\temergency_restart_interval = %ds", fpm_global_config.emergency_restart_interval);
 
1119
        zlog(ZLOG_NOTICE, "\temergency_restart_threshold = %d", fpm_global_config.emergency_restart_threshold);
 
1120
        zlog(ZLOG_NOTICE, " ");
 
1121
 
 
1122
        for (wp = fpm_worker_all_pools; wp; wp = wp->next) {
 
1123
                struct key_value_s *kv;
 
1124
                if (!wp->config) continue;
 
1125
                zlog(ZLOG_NOTICE, "[%s]", STR2STR(wp->config->name));
 
1126
                zlog(ZLOG_NOTICE, "\tprefix = %s", STR2STR(wp->config->prefix));
 
1127
                zlog(ZLOG_NOTICE, "\tuser = %s", STR2STR(wp->config->user));
 
1128
                zlog(ZLOG_NOTICE, "\tgroup = %s", STR2STR(wp->config->group));
 
1129
                zlog(ZLOG_NOTICE, "\tchroot = %s", STR2STR(wp->config->chroot));
 
1130
                zlog(ZLOG_NOTICE, "\tchdir = %s", STR2STR(wp->config->chdir));
 
1131
                zlog(ZLOG_NOTICE, "\tlisten = %s", STR2STR(wp->config->listen_address));
 
1132
                zlog(ZLOG_NOTICE, "\tlisten.backlog = %d", wp->config->listen_backlog);
 
1133
                zlog(ZLOG_NOTICE, "\tlisten.owner = %s", STR2STR(wp->config->listen_owner));
 
1134
                zlog(ZLOG_NOTICE, "\tlisten.group = %s", STR2STR(wp->config->listen_group));
 
1135
                zlog(ZLOG_NOTICE, "\tlisten.mode = %s", STR2STR(wp->config->listen_mode));
 
1136
                zlog(ZLOG_NOTICE, "\tlisten.allowed_clients = %s", STR2STR(wp->config->listen_allowed_clients));
 
1137
                zlog(ZLOG_NOTICE, "\tpm = %s", PM2STR(wp->config->pm));
 
1138
                zlog(ZLOG_NOTICE, "\tpm.max_children = %d", wp->config->pm_max_children);
 
1139
                zlog(ZLOG_NOTICE, "\tpm.max_requests = %d", wp->config->pm_max_requests);
 
1140
                zlog(ZLOG_NOTICE, "\tpm.start_servers = %d", wp->config->pm_start_servers);
 
1141
                zlog(ZLOG_NOTICE, "\tpm.min_spare_servers = %d", wp->config->pm_min_spare_servers);
 
1142
                zlog(ZLOG_NOTICE, "\tpm.max_spare_servers = %d", wp->config->pm_max_spare_servers);
 
1143
                zlog(ZLOG_NOTICE, "\tpm.status_path = %s", STR2STR(wp->config->pm_status_path));
 
1144
                zlog(ZLOG_NOTICE, "\tping.path = %s", STR2STR(wp->config->ping_path));
 
1145
                zlog(ZLOG_NOTICE, "\tping.response = %s", STR2STR(wp->config->ping_response));
 
1146
                zlog(ZLOG_NOTICE, "\tcatch_workers_output = %s", BOOL2STR(wp->config->catch_workers_output));
 
1147
                zlog(ZLOG_NOTICE, "\trequest_terminate_timeout = %ds", wp->config->request_terminate_timeout);
 
1148
                zlog(ZLOG_NOTICE, "\trequest_slowlog_timeout = %ds", wp->config->request_slowlog_timeout);
 
1149
                zlog(ZLOG_NOTICE, "\tslowlog = %s", STR2STR(wp->config->slowlog));
 
1150
                zlog(ZLOG_NOTICE, "\trlimit_files = %d", wp->config->rlimit_files);
 
1151
                zlog(ZLOG_NOTICE, "\trlimit_core = %d", wp->config->rlimit_core);
 
1152
 
 
1153
                for (kv = wp->config->env; kv; kv = kv->next) {
 
1154
                        zlog(ZLOG_NOTICE, "\tenv[%s] = %s", kv->key, kv->value);
 
1155
                }
 
1156
 
 
1157
                for (kv = wp->config->php_values; kv; kv = kv->next) {
 
1158
                        zlog(ZLOG_NOTICE, "\tphp_value[%s] = %s", kv->key, kv->value);
 
1159
                }
 
1160
 
 
1161
                for (kv = wp->config->php_admin_values; kv; kv = kv->next) {
 
1162
                        zlog(ZLOG_NOTICE, "\tphp_admin_value[%s] = %s", kv->key, kv->value);
 
1163
                }
 
1164
                zlog(ZLOG_NOTICE, " ");
 
1165
        }
 
1166
}
 
1167
/* }}} */
 
1168
 
 
1169
int fpm_conf_init_main(int test_conf) /* {{{ */
 
1170
{
990
1171
        int ret;
991
1172
        TSRMLS_FETCH();
992
1173
 
993
 
        if (filename == NULL) {
994
 
                spprintf(&filename, 0, "%s/php-fpm.conf", PHP_SYSCONFDIR);
995
 
                free = 1;
996
 
        }
997
 
 
998
 
        ret = fpm_conf_load_ini_file(filename TSRMLS_CC);
 
1174
        if (fpm_globals.prefix && *fpm_globals.prefix) {
 
1175
                if (!fpm_conf_is_dir(fpm_globals.prefix)) {
 
1176
                        zlog(ZLOG_ERROR, "the global prefix '%s' does not exist or is not a directory", fpm_globals.prefix);
 
1177
                        return -1;
 
1178
                }
 
1179
        }
 
1180
 
 
1181
        if (fpm_globals.config == NULL) {
 
1182
                char *tmp;
 
1183
 
 
1184
                if (fpm_globals.prefix == NULL) {
 
1185
                        spprintf(&tmp, 0, "%s/php-fpm.conf", PHP_SYSCONFDIR);
 
1186
                } else {
 
1187
                        spprintf(&tmp, 0, "%s/etc/php-fpm.conf", fpm_globals.prefix);
 
1188
                }
 
1189
 
 
1190
                if (!tmp) {
 
1191
                        zlog(ZLOG_SYSERROR, "spprintf() failed (tmp for fpm_globals.config)");
 
1192
                        return -1;
 
1193
                }
 
1194
 
 
1195
                fpm_globals.config = strdup(tmp);
 
1196
                efree(tmp);
 
1197
 
 
1198
                if (!fpm_globals.config) {
 
1199
                        zlog(ZLOG_SYSERROR, "spprintf() failed (fpm_globals.config)");
 
1200
                        return -1;
 
1201
                }
 
1202
        }
 
1203
 
 
1204
        ret = fpm_conf_load_ini_file(fpm_globals.config TSRMLS_CC);
999
1205
 
1000
1206
        if (0 > ret) {
1001
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "failed to load configuration file '%s'", filename);
1002
 
                if (free) efree(filename);
 
1207
                zlog(ZLOG_ERROR, "failed to load configuration file '%s'", fpm_globals.config);
1003
1208
                return -1;
1004
1209
        }
1005
1210
 
1006
 
        if (free) efree(filename);
1007
 
 
1008
1211
        if (0 > fpm_conf_post_process()) {
1009
 
                zlog(ZLOG_STUFF, ZLOG_ERROR, "failed to post process the configuration");
 
1212
                zlog(ZLOG_ERROR, "failed to post process the configuration");
 
1213
                return -1;
 
1214
        }
 
1215
 
 
1216
        if (test_conf) {
 
1217
                if (test_conf > 1) {
 
1218
                        fpm_conf_dump();
 
1219
                }
 
1220
                zlog(ZLOG_NOTICE, "configuration file %s test is successful\n", fpm_globals.config);
1010
1221
                return -1;
1011
1222
        }
1012
1223