Permalink
Browse files

As discussed, add --with-config-file-scan-dir compile-time switch def…

…ining

a directory which will be scanned for *.ini files after the main php.ini
file has been parsed.  This makes it much easier to automatically deploy
a modular PHP since adding extensions which have their own ini switches can
now be done by simply dropping a foo.ini file in the right directory and
restarting.  A list of parsed ini files is maintained and shown on the
phpinfo page.
  • Loading branch information...
1 parent 114dff3 commit 989a61ed98f1865ac926d114448f0ebfa3a8ec43 @rlerdorf rlerdorf committed Oct 4, 2002
Showing with 89 additions and 15 deletions.
  1. +2 −0 NEWS
  2. +8 −0 configure.in
  3. +8 −0 ext/standard/info.c
  4. +1 −0 main/build-defs.h.in
  5. +1 −0 main/main.c
  6. +69 −15 main/php_ini.c
View
2 NEWS
@@ -1,6 +1,8 @@
PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
? ? ??? 2002, Version 4.3.0
+- Added --with-config-file-scan-dir compile-time switch which specifies a
+ directory which will be scanned for *.ini files.
- Added wddx_serialize_type(). Allows users to cast values to WDDX types (jan)
- Added ob_flush_all() that flushes all buffers. (Yasuo)
- Added ob_get_clean() and og_get_flush(). (Yasuo)
View
@@ -570,6 +570,12 @@ if test "$PHP_CONFIG_FILE_PATH" = "DEFAULT"; then
esac
fi
+PHP_ARG_WITH(config-file-scan-dir,[directory to be scanned for configuration files],
+[ --with-config-file-scan-dir=PATH ], DEFAULT, no)
+if test "$PHP_CONFIG_FILE_SCAN_DIR" = "DEFAULT"; then
+ PHP_CONFIG_FILE_SCAN_DIR=""
+fi
+
# compatibility
if test -z "$with_pear" && test "$enable_pear" = "no"; then
with_pear=no
@@ -890,6 +896,7 @@ EXPANDED_LIBDIR=$libdir
EXPANDED_SYSCONFDIR=`eval echo $sysconfdir`
EXPANDED_DATADIR=$datadir
EXPANDED_PHP_CONFIG_FILE_PATH=`eval echo "$PHP_CONFIG_FILE_PATH"`
+EXPANDED_PHP_CONFIG_FILE_SCAN_DIR=`eval echo "$PHP_CONFIG_FILE_SCAN_DIR"`
INCLUDE_PATH=.:$EXPANDED_PEAR_INSTALLDIR
exec_prefix=$old_exec_prefix
@@ -905,6 +912,7 @@ AC_SUBST(EXPANDED_DATADIR)
AC_SUBST(EXPANDED_SYSCONFDIR)
AC_SUBST(EXPANDED_LOCALSTATEDIR)
AC_SUBST(EXPANDED_PHP_CONFIG_FILE_PATH)
+AC_SUBST(EXPANDED_PHP_CONFIG_FILE_SCAN_DIR)
PHP_UTILIZE_RPATHS
View
@@ -59,6 +59,7 @@ ZEND_EXTERN_MODULE_GLOBALS(iconv)
} \
PHPAPI extern char *php_ini_opened_path;
+PHPAPI extern char *php_ini_scanned_files;
/* {{{ _display_module_info
*/
@@ -378,6 +379,13 @@ PHPAPI void php_print_info(int flag TSRMLS_DC)
#endif
php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:PHP_CONFIG_FILE_PATH);
+
+ 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);
View
@@ -87,4 +87,5 @@
#define PHP_SYSCONFDIR "@EXPANDED_SYSCONFDIR@"
#define PHP_LOCALSTATEDIR "@EXPANDED_LOCALSTATEDIR@"
#define PHP_CONFIG_FILE_PATH "@EXPANDED_PHP_CONFIG_FILE_PATH@"
+#define PHP_CONFIG_FILE_SCAN_DIR "@EXPANDED_PHP_CONFIG_FILE_SCAN_DIR@"
#define PHP_SHLIB_SUFFIX "@SHLIB_SUFFIX_NAME@"
View
@@ -1108,6 +1108,7 @@ int php_module_startup(sapi_module_struct *sf, zend_module_entry *additional_mod
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SYSCONFDIR", PHP_SYSCONFDIR, sizeof(PHP_SYSCONFDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_LOCALSTATEDIR", PHP_LOCALSTATEDIR, sizeof(PHP_LOCALSTATEDIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, sizeof(PHP_CONFIG_FILE_PATH)-1, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS);
php_output_register_constants(TSRMLS_C);
php_rfc1867_register_constants(TSRMLS_C);
View
@@ -34,6 +34,10 @@
#include "SAPI.h"
#include "php_main.h"
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
typedef struct _php_extension_lists {
zend_llist engine;
zend_llist functions;
@@ -44,6 +48,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_files=NULL;
/* {{{ php_ini_displayer_cb
*/
@@ -228,6 +233,14 @@ int php_init_config()
char *open_basedir;
int free_ini_search_path=0;
zend_file_handle fh;
+ DIR *dirp = NULL;
+ struct dirent *dir_entry;
+ struct stat sb;
+ char ini_file[MAXPATHLEN];
+ char *p;
+ zend_llist scanned_ini_list;
+ int l, total_l=0;
+ zend_llist_element *element;
TSRMLS_FETCH();
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
@@ -236,6 +249,7 @@ int php_init_config()
zend_llist_init(&extension_lists.engine, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
zend_llist_init(&extension_lists.functions, sizeof(zval), (llist_dtor_func_t) ZVAL_DESTRUCTOR, 1);
+ zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
safe_mode_state = PG(safe_mode);
open_basedir = PG(open_basedir);
@@ -363,25 +377,62 @@ int php_init_config()
PG(safe_mode) = safe_mode_state;
PG(open_basedir) = open_basedir;
- if (!fh.handle.fp) {
- return SUCCESS; /* having no configuration file is ok */
- }
- fh.type = ZEND_HANDLE_FP;
+ if (fh.handle.fp) {
+ fh.type = ZEND_HANDLE_FP;
- zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
+ zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
- {
- zval tmp;
+ {
+ zval tmp;
- Z_STRLEN(tmp) = strlen(fh.filename);
- Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
- Z_TYPE(tmp) = IS_STRING;
- zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
- if(php_ini_opened_path)
- efree(php_ini_opened_path);
- php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
+ Z_STRLEN(tmp) = strlen(fh.filename);
+ Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
+ Z_TYPE(tmp) = IS_STRING;
+ zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"), (void *) &tmp, sizeof(zval), NULL);
+ if(php_ini_opened_path)
+ efree(php_ini_opened_path);
+ php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
+ }
+ }
+
+ /* 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(strlen(PHP_CONFIG_FILE_SCAN_DIR)) {
+ dirp = VCWD_OPENDIR(PHP_CONFIG_FILE_SCAN_DIR);
+ if (dirp) {
+ fh.type = ZEND_HANDLE_FP;
+ while ((dir_entry = readdir(dirp)) != NULL) {
+ /* check for a .ini extension */
+ if ((p = strrchr(dir_entry->d_name,'.')) && strcmp(p,".ini")) continue;
+ snprintf(ini_file, MAXPATHLEN, "%s%c%s", PHP_CONFIG_FILE_SCAN_DIR, DEFAULT_SLASH, dir_entry->d_name);
+ if (VCWD_STAT(ini_file, &sb) == 0) {
+ if (S_ISREG(sb.st_mode)) {
+ if ((fh.handle.fp = VCWD_FOPEN(ini_file, "r"))) {
+ fh.filename = ini_file;
+ zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, &extension_lists);
+ /* Here, add it to the list of ini files read */
+ l = strlen(ini_file);
+ total_l += l+2;
+ p = estrndup(ini_file,l);
+ zend_llist_add_element(&scanned_ini_list, &p);
+ }
+ }
+ }
+ }
+ closedir(dirp);
+ /*
+ * Don't need an extra byte for the \0 in this malloc as the last
+ * element will not get a trailing , which gives us the byte for the \0
+ */
+ php_ini_scanned_files = (char *)malloc(total_l);
+ *php_ini_scanned_files = '\0';
+ for (element=scanned_ini_list.head; element; element=element->next) {
+ strcat(php_ini_scanned_files,*(char **)element->data);
+ strcat(php_ini_scanned_files,element->next ? ",\n":"\n");
+ }
+ zend_llist_destroy(&scanned_ini_list);
+ }
}
-
return SUCCESS;
}
/* }}} */
@@ -394,6 +445,9 @@ int php_shutdown_config(void)
if (php_ini_opened_path) {
free(php_ini_opened_path);
}
+ if (php_ini_scanned_files) {
+ free(php_ini_scanned_files);
+ }
return SUCCESS;
}
/* }}} */

0 comments on commit 989a61e

Please sign in to comment.