Skip to content

Commit

Permalink
- Fixed few logic errors in php*.ini search path creation as document…
Browse files Browse the repository at this point in the history
…ed here:

   http://fi.php.net/manual/en/configuration.php#configuration.file

#
# Before this patch:
#
# $ strace php -r 'echo 1;' 2>&1 | grep php.ini
# open("/www/php/lib/php.ini", O_RDONLY)  = 3
# lstat64("/www/php/lib/php.ini", {st_mode=S_IFREG|0640, st_size=46264, ...}) = 0
#
# With this patch:
#
# $ strace php -r 'echo 1;' 2>&1 | grep php.ini
# open("./php.ini", O_RDONLY)             = -1 ENOENT (No such file or directory)
# open("/usr/src/php5_1_full/sapi/cli/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)
# open("/www/php/lib/php.ini", O_RDONLY)  = 3
# lstat64("/www/php/lib/php.ini", {st_mode=S_IFREG|0640, st_size=46264, ...}) = 0
#
  • Loading branch information
foobar committed Jul 29, 2005
1 parent b325b34 commit f66d5f0
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions main/php_ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

/* $Id$ */

/* Check CWD for php.ini */
#define INI_CHECK_CWD

#include "php.h"
#include "ext/standard/info.h"
#include "zend_ini.h"
Expand Down Expand Up @@ -261,11 +258,10 @@ static void php_load_zend_extension_cb(void *arg TSRMLS_DC)
*/
int php_init_config()
{
char *env_location, *php_ini_search_path;
char *binary_location;
char *php_ini_search_path = NULL;
int safe_mode_state;
char *open_basedir;
int free_ini_search_path=0;
int free_ini_search_path = 0;
zend_file_handle fh;
struct stat sb;
char ini_file[MAXPATHLEN];
Expand All @@ -290,38 +286,42 @@ int php_init_config()
safe_mode_state = PG(safe_mode);
open_basedir = PG(open_basedir);

env_location = getenv("PHPRC");
if (!env_location) {
env_location = "";
}
if (sapi_module.php_ini_path_override) {
php_ini_search_path = sapi_module.php_ini_path_override;
free_ini_search_path = 0;
} else {
} else if (!sapi_module.php_ini_ignore) {
char *default_location;
char *env_location;
char *binary_location;
static const char paths_separator[] = { ZEND_PATHS_SEPARATOR, 0 };
#ifdef PHP_WIN32
char *reg_location;
#endif

env_location = getenv("PHPRC");
if (!env_location) {
env_location = "";
}

/*
* Prepare search path
*/

php_ini_search_path = (char *) emalloc(MAXPATHLEN * 4 + strlen(env_location) + 3 + 1);
free_ini_search_path = 1;
php_ini_search_path[0] = 0;

#ifdef PHP_WIN32
/* Add registry location */
reg_location = GetIniPathFromRegistry();
if(reg_location != NULL) {
if (reg_location != NULL) {
if (*php_ini_search_path) {
strcat(php_ini_search_path, paths_separator);
}
strcat(php_ini_search_path, reg_location);
efree(reg_location);
}
#endif
/*
* Prepare search path
*/

/* Add environment location */
if (env_location[0]) {
Expand All @@ -331,15 +331,13 @@ int php_init_config()
strcat(php_ini_search_path, env_location);
}

/* Add cwd */
#ifdef INI_CHECK_CWD
if (strcmp(sapi_module.name, "cli") != 0) {
/* Add cwd (only with CLI) */
if (strcmp(sapi_module.name, "cli") == 0) {
if (*php_ini_search_path) {
strcat(php_ini_search_path, paths_separator);
}
strcat(php_ini_search_path, ".");
}
#endif

/* Add binary directory */
#ifdef PHP_WIN32
Expand Down

0 comments on commit f66d5f0

Please sign in to comment.