]> granicus.if.org Git - php/commitdiff
MFH: [DOC]- Added methods to change/disable --with-config-file-scan-dir=PATH at
authorJani Taskinen <jani@php.net>
Wed, 13 Aug 2008 01:01:29 +0000 (01:01 +0000)
committerJani Taskinen <jani@php.net>
Wed, 13 Aug 2008 01:01:29 +0000 (01:01 +0000)
MFH: [DOC]  startup:
MFH: [DOC]
MFH: [DOC]  To disable: Override default php.ini by using both -c and -n with
MFH: [DOC]              CGI/CLI or set "PHP_INI_SCAN_DIR" environment variable
MFH: [DOC]              to an empty string.
MFH: [DOC]
MFH: [DOC]  To change: Simply set "PHP_INI_SCAN_DIR" environment variable to point
MFH: [DOC]             to another path.
MFH: - Fixed bug #42604 ("make test" fails with  --with-config-file-scan-dir=/some/path)
MFH: - Implemented FR #45114 (Option to change --with-config-file-scan-dir)

Makefile.global
NEWS
ext/standard/info.c
main/php_ini.c
sapi/cgi/cgi_main.c
sapi/cli/php_cli.c
sapi/milter/php_milter.c

index e0d4596ebc2fba84c20fd86dde51b1a35013492a..6a62d72478e33dcd0302f1f15b8151ae17d4d390 100644 (file)
@@ -87,16 +87,21 @@ test: all
                CC="$(CC)" \
                        $(PHP_EXECUTABLE) $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -d extension_dir=modules/ $(PHP_TEST_SHARED_EXTENSIONS) tests/; \
        elif test ! -z "$(SAPI_CLI_PATH)" && test -x "$(SAPI_CLI_PATH)"; then \
-               INI_FILE=`$(top_builddir)/$(SAPI_CLI_PATH) -r 'echo php_ini_loaded_file();'`; \
+               INI_FILE=`$(top_builddir)/$(SAPI_CLI_PATH) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \
                if test "$$INI_FILE"; then \
                        $(EGREP) -v '^(zend_)?extension(_debug)?(_ts)?[\t\ ]*=' "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \
                else \
                        echo > $(top_builddir)/tmp-php.ini; \
                fi; \
+               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`; \
+               if test "$$INI_SCANNED_PATH"; then \
+                       INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \
+                       $(EGREP) -h -v '^(zend_)?extension(_debug)?(_ts)?[\t\ ]*=' "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \
+               fi; \
                TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
                TEST_PHP_SRCDIR=$(top_srcdir) \
                CC="$(CC)" \
-                       $(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); \
+                       $(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); \
        else \
                echo "ERROR: Cannot run tests without CLI sapi."; \
        fi
diff --git a/NEWS b/NEWS
index 46dcc7d31546cd311194f40270b4b00d92489cd1..c29169a5cc18de1f92e52c9ffe019517f7f9adcb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ PHP                                                                        NEWS
 - Reverted fix for bug #44197 due to behaviour change in minor version.
   (Felipe)
 
+- Added "PHP_INI_SCAN_DIR" environment variable which can be used to either
+  disable or change the compile time ini scan directory (FR 45114). (Jani)
+
 - Fixed security issues detailed in CVE-2008-2665 and CVE-2008-2666.
   (Christian Hoffmann)
 - Fixed simplexml asXML() not to lose encoding when dumping entire document
@@ -73,6 +76,8 @@ PHP                                                                        NEWS
   (Jani)
 - Fixed bug #43993 (mb_substr_count() behaves differently to substr_count() with
   overlapping needles). (Moriyoshi)
+- Fixed bug #42604 ("make test" fails with --with-config-file-scan-dir=path).
+  (Jani)
 - Fixed bug #41348 (OCI8: allow compilation with Oracle 8.1). (Chris Jones)
 
 01 May 2008, PHP 5.2.6
index 0c3118a78b5fe4ba79874d1b14c7fafcc77f5798..aceb594e99b26dde6213fba2ab02f49ffc0a4257 100644 (file)
@@ -57,6 +57,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
                                                } \
 
 PHPAPI extern char *php_ini_opened_path;
+PHPAPI extern char *php_ini_scanned_path;
 PHPAPI extern char *php_ini_scanned_files;
        
 static int php_info_write_wrapper(const char *str, uint str_length)
@@ -501,14 +502,9 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
 
                php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
                php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
+               php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
+               php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
 
-               if (strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
-                       php_info_print_table_row(2, "Scan this dir for additional .ini files", PHP_CONFIG_FILE_SCAN_DIR);
-                       if (php_ini_scanned_files) {
-                               php_info_print_table_row(2, "additional .ini files parsed", php_ini_scanned_files);
-                       }
-               }
-               
                snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
                php_info_print_table_row(2, "PHP API", temp_api);
 
index bb52975f633d3e537491274cb23257090e8af4df..498cac1e3bfa4c0b1a611474a88c1e299e0edcce 100644 (file)
@@ -50,6 +50,7 @@ typedef struct _php_extension_lists {
 static HashTable configuration_hash;
 PHPAPI char *php_ini_opened_path=NULL;
 static php_extension_lists extension_lists;
+PHPAPI char *php_ini_scanned_path=NULL;
 PHPAPI char *php_ini_scanned_files=NULL;
 
 /* {{{ php_ini_displayer_cb
@@ -448,9 +449,18 @@ int php_init_config(TSRMLS_D)
        PG(safe_mode) = 0;
        PG(open_basedir) = NULL;
 
+       /*
+        * Find and open actual ini file
+        */
+
        memset(&fh, 0, sizeof(fh));
-       /* Check if php_ini_path_override is a file */
-       if (!sapi_module.php_ini_ignore) {
+
+       /* If SAPI does not want to ignore all ini files OR an overriding file/path is given.
+        * This allows disabling scanning for ini files in the PHP_CONFIG_FILE_SCAN_DIR but still
+        * load an optional ini file. */
+       if (!sapi_module.php_ini_ignore || sapi_module.php_ini_path_override) {
+
+               /* Check if php_ini_file_name is a file and can be opened */
                if (php_ini_file_name && php_ini_file_name[0]) {
                        struct stat statbuf;
 
@@ -463,7 +473,8 @@ int php_init_config(TSRMLS_D)
                                }
                        }
                }
-               /* Search php-%sapi-module-name%.ini file in search path */
+
+               /* Otherwise search for php-%sapi-module-name%.ini file in search path */
                if (!fh.handle.fp) {
                        const char *fmt = "php-%s.ini";
                        char *ini_fname;
@@ -474,7 +485,8 @@ int php_init_config(TSRMLS_D)
                                fh.filename = php_ini_opened_path;
                        }
                }
-               /* Search php.ini file in search path */
+
+               /* If still no ini file found, search for php.ini file in search path */
                if (!fh.handle.fp) {
                        fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
                        if (fh.handle.fp) {
@@ -509,20 +521,31 @@ int php_init_config(TSRMLS_D)
                }
        }
 
-       /* If the config_file_scan_dir is set at compile-time, go and scan this directory and
-        * parse any .ini files found in this directory. */
-       if (!sapi_module.php_ini_ignore && strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
+       /* Check for PHP_INI_SCAN_DIR environment variable to override/set config file scan directory */
+       php_ini_scanned_path = getenv("PHP_INI_SCAN_DIR");
+       if (!php_ini_scanned_path) {
+               /* Or fall back using possible --with-config-file-scan-dir setting (defaults to empty string!) */
+               php_ini_scanned_path = PHP_CONFIG_FILE_SCAN_DIR;
+       }
+       int php_ini_scanned_path_len = strlen(php_ini_scanned_path);
+
+       /* Scan and parse any .ini files found in scan path if path not empty. */
+       if (!sapi_module.php_ini_ignore && php_ini_scanned_path_len) {
                struct dirent **namelist;
                int ndir, i;
 
-               if ((ndir = php_scandir(PHP_CONFIG_FILE_SCAN_DIR, &namelist, 0, php_alphasort)) > 0) {
+               if ((ndir = php_scandir(php_ini_scanned_path, &namelist, 0, php_alphasort)) > 0) {
                        for (i = 0; i < ndir; i++) {
                                /* check for a .ini extension */
                                if (!(p = strrchr(namelist[i]->d_name, '.')) || (p && strcmp(p, ".ini"))) {
                                        free(namelist[i]);
                                        continue;
                                }
-                               snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, namelist[i]->d_name);
+                               if (IS_SLASH(php_ini_scanned_path[php_ini_scanned_path_len - 1])) {
+                                       snprintf(ini_file, MAXPATHLEN, "%s%s", php_ini_scanned_path, namelist[i]->d_name);
+                               } else {
+                                       snprintf(ini_file, MAXPATHLEN, "%s%c%s", php_ini_scanned_path, DEFAULT_SLASH, namelist[i]->d_name);
+                               }
                                if (VCWD_STAT(ini_file, &sb) == 0) {
                                        if (S_ISREG(sb.st_mode)) {
                                                if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
@@ -555,6 +578,9 @@ int php_init_config(TSRMLS_D)
                        }
                        zend_llist_destroy(&scanned_ini_list);
                }
+       } else {
+               /* Make sure an empty php_ini_scanned_path ends up as NULL */
+               php_ini_scanned_path = NULL;
        }
 
        if (sapi_module.ini_entries) {
index deb359108d5b827a89fbe30f87ebc23bc6c78610..37c7909e1347406dec5533e7e92eda7bde3dbe24 100644 (file)
@@ -1678,17 +1678,6 @@ consult the installation file that came with this distribution, or visit \n\
                        && !fastcgi
 #endif
                ) {
-                       if (cgi_sapi_module.php_ini_path_override && cgi_sapi_module.php_ini_ignore) {
-                               no_headers = 1;
-                               php_output_startup();
-                               php_output_activate(TSRMLS_C);
-                               SG(headers_sent) = 1;
-                               php_printf("You cannot use both -n and -c switch. Use -h for help.\n");
-                               php_end_ob_buffers(1 TSRMLS_CC);
-                               exit_status = 1;
-                               goto out;
-                       }
-
                        while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
                                switch (c) {
 
index a076dfdcdc9b90588e045856cb771f4ffc79131b..e3f35991131c66191600200740f887032b683809 100644 (file)
@@ -729,12 +729,6 @@ int main(int argc, char *argv[])
                CG(in_compilation) = 0; /* not initialized but needed for several options */
                EG(uninitialized_zval_ptr) = NULL;
 
-               if (cli_sapi_module.php_ini_path_override && cli_sapi_module.php_ini_ignore) {
-                       PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
-                       exit_status=1;
-                       goto out_err;
-               }
-
                while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0)) != -1) {
                        switch (c) {
 
index d551ead12ffc45943a5cee3196aa22918d130678..567fc8f27a560d7b8a913e986e32892ec7de4d37 100644 (file)
@@ -18,6 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
+/* $Id$ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -1006,13 +1007,6 @@ int main(int argc, char *argv[])
 
                zend_uv.html_errors = 0; /* tell the engine we're in non-html mode */
 
-               if (milter_sapi_module.php_ini_path_override && milter_sapi_module.php_ini_ignore) {
-                       SG(headers_sent) = 1;
-                       SG(request_info).no_headers = 1;
-                       PUTS("You cannot use both -n and -c switch. Use -h for help.\n");
-                       exit(1);
-               }
-       
                while ((c = ap_php_getopt(argc, argv, OPTSTRING)) != -1) {
                        switch (c) {