Skip to content

Commit bc6a9ad

Browse files
author
Jani Taskinen
committed
[DOC]- Added methods to change/disable --with-config-file-scan-dir=PATH at
[DOC] startup: [DOC] [DOC] To disable: Override default php.ini by using both -c and -n with [DOC] CGI/CLI or set "PHP_INI_SCAN_DIR" environment variable [DOC] to an empty string. [DOC] [DOC] To change: Simply set "PHP_INI_SCAN_DIR" environment variable to point [DOC] to another path. - Fixed bug #42604 ("make test" fails with --with-config-file-scan-dir=/some/path) - Implemented FR #45114 (Option to change --with-config-file-scan-dir)
1 parent a99fad3 commit bc6a9ad

File tree

6 files changed

+46
-40
lines changed

6 files changed

+46
-40
lines changed

Makefile.global

Lines changed: 7 additions & 2 deletions
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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
5959
} \
6060

6161
PHPAPI extern char *php_ini_opened_path;
62+
PHPAPI extern char *php_ini_scanned_path;
6263
PHPAPI extern char *php_ini_scanned_files;
6364

6465
static int php_info_print_html_esc(const char *str, int len) /* {{{ */
@@ -567,14 +568,9 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
567568

568569
php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
569570
php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
571+
php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
572+
php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
570573

571-
if (strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
572-
php_info_print_table_row(2, "Scan this dir for additional .ini files", PHP_CONFIG_FILE_SCAN_DIR);
573-
if (php_ini_scanned_files) {
574-
php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files);
575-
}
576-
}
577-
578574
snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
579575
php_info_print_table_row(2, "PHP API", temp_api);
580576

main/php_ini.c

Lines changed: 35 additions & 9 deletions
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
@@ -517,9 +518,18 @@ int php_init_config(TSRMLS_D)
517518

518519
PG(open_basedir) = NULL;
519520

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

@@ -532,7 +542,8 @@ int php_init_config(TSRMLS_D)
532542
}
533543
}
534544
}
535-
/* Search php-%sapi-module-name%.ini file in search path */
545+
546+
/* Otherwise search for php-%sapi-module-name%.ini file in search path */
536547
if (!fh.handle.fp) {
537548
const char *fmt = "php-%s.ini";
538549
char *ini_fname;
@@ -543,7 +554,8 @@ int php_init_config(TSRMLS_D)
543554
fh.filename = php_ini_opened_path;
544555
}
545556
}
546-
/* Search php.ini file in search path */
557+
558+
/* If still no ini file found, search for php.ini file in search path */
547559
if (!fh.handle.fp) {
548560
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
549561
if (fh.handle.fp) {
@@ -580,9 +592,16 @@ int php_init_config(TSRMLS_D)
580592
}
581593
}
582594

583-
/* If the config_file_scan_dir is set at compile-time, go and scan this directory and
584-
* parse any .ini files found in this directory. */
585-
if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
595+
/* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
596+
php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
597+
if (!php_ini_scanned_path) {
598+
/* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
599+
php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
600+
}
601+
int php_ini_scanned_path_len = strlen(php_ini_scanned_path);
602+
603+
/* Scan and parse any .ini files found in scan path if path not empty. */
604+
if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
586605
struct dirent **namelist;
587606
int ndir, i;
588607
struct stat sb;
@@ -596,7 +615,7 @@ int php_init_config(TSRMLS_D)
596615
/* Reset active ini section */
597616
RESET_ACTIVE_INI_HASH();
598617

599-
if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
618+
if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
600619
zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
601620
memset(&fh, 0, sizeof(fh));
602621

@@ -607,7 +626,11 @@ int php_init_config(TSRMLS_D)
607626
free(namelist[i]);
608627
continue;
609628
}
610-
snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
629+
if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
630+
snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
631+
} else {
632+
snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
633+
}
611634
if (VCWD_STAT(ini_file, &sb) == 0) {
612635
if (S_ISREG(sb.st_mode)) {
613636
if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
@@ -645,6 +668,9 @@ int php_init_config(TSRMLS_D)
645668
}
646669
zend_llist_destroy(&scanned_ini_list);
647670
}
671+
} else {
672+
/* Make sure an empty php_ini_scanned_path ends up as NULL */
673+
php_ini_scanned_path = NULL;
648674
}
649675

650676
if (sapi_module.ini_entries) {

sapi/cgi/cgi_main.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,15 +1734,6 @@ consult the installation file that came with this distribution, or visit \n\
17341734
CG(interactive) = 0;
17351735

17361736
if (!cgi && !fastcgi) {
1737-
if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) {
1738-
no_headers = 1;
1739-
SG(headers_sent) = 1;
1740-
php_printf("You cannot use both -n and -c switch. Use -h for help.\n");
1741-
php_output_end_all(TSRMLS_C);
1742-
exit_status = 1;
1743-
goto out;
1744-
}
1745-
17461737
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
17471738
switch (c) {
17481739

sapi/cli/php_cli.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,6 @@ int main(int argc, char *argv[])
760760
CG(in_compilation) = 0; /* not initialized but needed for several options */
761761
EG(uninitialized_zval_ptr) = NULL;
762762

763-
if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
764-
PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
765-
exit_status=1;
766-
goto err;
767-
}
768-
769763
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
770764
switch (c) {
771765

sapi/milter/php_milter.c

Lines changed: 1 addition & 7 deletions
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"
@@ -1057,13 +1058,6 @@ int main(int argc, char *argv[])
10571058

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

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

0 commit comments

Comments
 (0)