Skip to content

Commit e5e6f55

Browse files
author
Jani Taskinen
committed
MFH
1 parent f87d453 commit e5e6f55

File tree

6 files changed

+46
-42
lines changed

6 files changed

+46
-42
lines changed

Makefile.global

+7-2
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,21 @@ test: all
8787
CC="$(CC)" \
8888
$(PHP_EXECUTABLE) $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -d extension_dir=modules/ $(PHP_TEST_SHARED_EXTENSIONS) tests/; \
8989
elif test ! -z "$(SAPI_CLI_PATH)" && test -x "$(SAPI_CLI_PATH)"; then \
90-
INI_FILE=`$(top_builddir)/$(SAPI_CLI_PATH) -r 'echo php_ini_loaded_file();'`; \
90+
INI_FILE=`$(top_builddir)/$(SAPI_CLI_PATH) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \
9191
if test "$$INI_FILE"; then \
9292
$(EGREP) -v '^(zend_)?extension(_debug)?(_ts)?[\t\ ]*=' "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \
9393
else \
9494
echo > $(top_builddir)/tmp-php.ini; \
9595
fi; \
96+
INI_SCANNED_PATH=`$(top_builddir)/$(SAPI_CLI_PATH) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/null`; \
97+
if test "$$INI_SCANNED_PATH"; then \
98+
INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \
99+
$(EGREP) -h -v '^(zend_)?extension(_debug)?(_ts)?[\t\ ]*=' "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \
100+
fi; \
96101
TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
97102
TEST_PHP_SRCDIR=$(top_srcdir) \
98103
CC="$(CC)" \
99-
$(top_builddir)/$(SAPI_CLI_PATH) $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -c $(top_builddir)/tmp-php.ini -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS) $(TESTS); \
104+
$(top_builddir)/$(SAPI_CLI_PATH) -n -c $(top_builddir)/tmp-php.ini $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -n -c $(top_builddir)/tmp-php.ini -d extension_dir=$(top_builddir)/modules/ $(PHP_TEST_SHARED_EXTENSIONS) $(TESTS); \
100105
else \
101106
echo "ERROR: Cannot run tests without CLI sapi."; \
102107
fi

ext/standard/info.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
5757
} \
5858

5959
PHPAPI extern char *php_ini_opened_path;
60+
PHPAPI extern char *php_ini_scanned_path;
6061
PHPAPI extern char *php_ini_scanned_files;
6162

6263
static int php_info_write_wrapper(const char *str, uint str_length)
@@ -483,14 +484,9 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
483484

484485
php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
485486
php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
487+
php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
488+
php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
486489

487-
if (strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
488-
php_info_print_table_row(2, "Scan this dir for additional .ini files", PHP_CONFIG_FILE_SCAN_DIR);
489-
if (php_ini_scanned_files) {
490-
php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files);
491-
}
492-
}
493-
494490
snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
495491
php_info_print_table_row(2, "PHP API", temp_api);
496492

main/php_ini.c

+35-9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static int has_per_dir_config = 0;
5454
static int has_per_host_config = 0;
5555
PHPAPI char *php_ini_opened_path=NULL;
5656
static php_extension_lists extension_lists;
57+
PHPAPI char *php_ini_scanned_path=NULL;
5758
PHPAPI char *php_ini_scanned_files=NULL;
5859

5960
/* {{{ php_ini_displayer_cb
@@ -520,9 +521,18 @@ int php_init_config(TSRMLS_D)
520521
PG(safe_mode) = 0;
521522
PG(open_basedir) = NULL;
522523

524+
/*
525+
* Find and open actual ini file
526+
*/
527+
523528
memset(&fh, 0, sizeof(fh));
524-
/* Check if php_ini_path_override is a file */
525-
if (!sapi_module.php_ini_ignore) {
529+
530+
/* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
531+
* This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
532+
* load an optional ini file. */
533+
if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
534+
535+
/* Check if php_ini_file_name is a file and can be opened */
526536
if (php_ini_file_name && php_ini_file_name[0]) {
527537
struct stat statbuf;
528538

@@ -535,7 +545,8 @@ int php_init_config(TSRMLS_D)
535545
}
536546
}
537547
}
538-
/* Search php-%sapi-module-name%.ini file in search path */
548+
549+
/* Otherwise search for php-%sapi-module-name%.ini file in search path */
539550
if (!fh.handle.fp) {
540551
const char *fmt = "php-%s.ini";
541552
char *ini_fname;
@@ -546,7 +557,8 @@ int php_init_config(TSRMLS_D)
546557
fh.filename = php_ini_opened_path;
547558
}
548559
}
549-
/* Search php.ini file in search path */
560+
561+
/* If still no ini file found, search for php.ini file in search path */
550562
if (!fh.handle.fp) {
551563
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
552564
if (fh.handle.fp) {
@@ -584,9 +596,16 @@ int php_init_config(TSRMLS_D)
584596
}
585597
}
586598

587-
/* If the config_file_scan_dir is set at compile-time, go and scan this directory and
588-
* parse any .ini files found in this directory. */
589-
if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
599+
/* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
600+
php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
601+
if (!php_ini_scanned_path) {
602+
/* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
603+
php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
604+
}
605+
int php_ini_scanned_path_len = strlen(php_ini_scanned_path);
606+
607+
/* Scan and parse any .ini files found in scan path if path not empty. */
608+
if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
590609
struct dirent **namelist;
591610
int ndir, i;
592611
struct stat sb;
@@ -600,7 +619,7 @@ int php_init_config(TSRMLS_D)
600619
/* Reset active ini section */
601620
RESET_ACTIVE_INI_HASH();
602621

603-
if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
622+
if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
604623
zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
605624
memset(&fh, 0, sizeof(fh));
606625

@@ -611,7 +630,11 @@ int php_init_config(TSRMLS_D)
611630
free(namelist[i]);
612631
continue;
613632
}
614-
snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
633+
if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
634+
snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
635+
} else {
636+
snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
637+
}
615638
if (VCWD_STAT(ini_file, &sb) == 0) {
616639
if (S_ISREG(sb.st_mode)) {
617640
if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
@@ -649,6 +672,9 @@ int php_init_config(TSRMLS_D)
649672
}
650673
zend_llist_destroy(&scanned_ini_list);
651674
}
675+
} else {
676+
/* Make sure an empty php_ini_scanned_path ends up as NULL */
677+
php_ini_scanned_path = NULL;
652678
}
653679

654680
if (sapi_module.ini_entries) {

sapi/cgi/cgi_main.c

-11
Original file line numberDiff line numberDiff line change
@@ -1725,17 +1725,6 @@ consult the installation file that came with this distribution, or visit \n\
17251725
CG(interactive) = 0;
17261726

17271727
if (!cgi && !fastcgi) {
1728-
if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) {
1729-
no_headers = 1;
1730-
php_output_startup();
1731-
php_output_activate(TSRMLS_C);
1732-
SG(headers_sent) = 1;
1733-
php_printf("You cannot use both -n and -c switch. Use -h for help.\n");
1734-
php_end_ob_buffers(1 TSRMLS_CC);
1735-
exit_status = 1;
1736-
goto out;
1737-
}
1738-
17391728
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
17401729
switch (c) {
17411730

sapi/cli/php_cli.c

-6
Original file line numberDiff line numberDiff line change
@@ -727,12 +727,6 @@ int main(int argc, char *argv[])
727727
CG(in_compilation) = 0; /* not initialized but needed for several options */
728728
EG(uninitialized_zval_ptr) = NULL;
729729

730-
if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
731-
PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
732-
exit_status=1;
733-
goto out_err;
734-
}
735-
736730
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
737731
switch (c) {
738732

sapi/milter/php_milter.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
+----------------------------------------------------------------------+
1919
*/
2020

21+
/* $Id$ */
2122

2223
#include "php.h"
2324
#include "php_globals.h"
@@ -1058,13 +1059,6 @@ int main(int argc, char *argv[])
10581059

10591060
zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
10601061

1061-
if (milter_sapi_module.php_ini_path_override && milter_sapi_module.php_ini_ignore) {
1062-
SG(headers_sent) = 1;
1063-
SG(request_info).no_headers = 1;
1064-
PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
1065-
exit(1);
1066-
}
1067-
10681062
while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
10691063
switch (c) {
10701064

0 commit comments

Comments
 (0)