]>
Commit | Line | Data |
---|---|---|
1 | to test which is main php.ini: | |
2 | $ php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));' | |
3 | ||
4 | https://github.com/pld-linux/php/commit/762ec2e | |
5 | ||
6 | --- php-7.0.0RC6.orig/main/php_ini.c 2015-11-10 23:58:52.227101032 +0200 | |
7 | +++ php-7.0.0RC6/main/php_ini.c 2015-11-11 00:01:43.502674750 +0200 | |
8 | @@ -375,12 +375,19 @@ | |
9 | } | |
10 | /* }}} */ | |
11 | ||
12 | +static int php_csort(const struct dirent **a, const struct dirent **b) | |
13 | +{ | |
14 | + return strcmp((*a)->d_name,(*b)->d_name); | |
15 | +} | |
16 | + | |
17 | /* {{{ php_init_config | |
18 | */ | |
19 | int php_init_config(void) | |
20 | { | |
21 | char *php_ini_file_name = NULL; | |
22 | char *php_ini_search_path = NULL; | |
23 | + // value for php_ini_loaded_file() to be stored into php_ini_opened_path | |
24 | + char *php_ini_loaded_file = NULL; | |
25 | int php_ini_scanned_path_len; | |
26 | char *open_basedir; | |
27 | int free_ini_search_path = 0; | |
28 | @@ -557,8 +564,26 @@ | |
29 | } | |
30 | } | |
31 | } | |
32 | + /* Search (global) php.ini file in search path */ | |
33 | + if (!fh.handle.fp) { | |
34 | + fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path); | |
35 | + if (fh.handle.fp) { | |
36 | + fh.filename = ZSTR_VAL(opened_path); | |
37 | + | |
38 | + // parse the ini file now | |
39 | + PG(open_basedir) = open_basedir; | |
40 | + fh.type = ZEND_HANDLE_FP; | |
41 | + zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC); | |
42 | + open_basedir = PG(open_basedir); | |
43 | + PG(open_basedir) = NULL; | |
44 | + fh.handle.fp = NULL; | |
45 | + | |
46 | + php_ini_loaded_file = estrdup(fh.filename); | |
47 | + fh.filename = NULL; | |
48 | + } | |
49 | + } | |
50 | ||
51 | - /* Otherwise search for php-%sapi-module-name%.ini file in search path */ | |
52 | + /* Also search for php-%sapi-module-name%.ini file in search path */ | |
53 | if (!fh.handle.fp) { | |
54 | const char *fmt = "php-%s.ini"; | |
55 | char *ini_fname; | |
56 | @@ -568,15 +593,8 @@ | |
57 | if (fh.handle.fp) { | |
58 | fh.filename = ZSTR_VAL(opened_path); | |
59 | } | |
60 | - } | |
61 | ||
62 | - /* If still no ini file found, search for php.ini file in search path */ | |
63 | - if (!fh.handle.fp) { | |
64 | - fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path); | |
65 | - if (fh.handle.fp) { | |
66 | - fh.filename = ZSTR_VAL(opened_path); | |
67 | - } | |
68 | - } | |
69 | + } | |
70 | } | |
71 | ||
72 | if (free_ini_search_path) { | |
73 | @@ -593,14 +611,28 @@ | |
74 | ||
75 | { | |
76 | zval tmp; | |
77 | + // use main php.ini if loaded | |
78 | + // see https://github.com/pld-linux/php/commit/762ec2e | |
79 | + // test with: | |
80 | + // php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));' | |
81 | + if (php_ini_loaded_file) { | |
82 | + if (fh.filename) { | |
83 | + efree((char *)fh.filename); | |
84 | + } | |
85 | + fh.filename = php_ini_loaded_file; | |
86 | + } | |
87 | ||
88 | ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1)); | |
89 | zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp); | |
90 | if (opened_path) { | |
91 | zend_string_release_ex(opened_path, 0); | |
92 | - } else { | |
93 | + } | |
94 | + | |
95 | + if (fh.filename) { | |
96 | efree((char *)fh.filename); | |
97 | + fh.filename = NULL; | |
98 | } | |
99 | + | |
100 | php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp)); | |
101 | } | |
102 | } | |
103 | @@ -624,13 +656,15 @@ | |
104 | zend_llist scanned_ini_list; | |
105 | zend_llist_element *element; | |
106 | int l, total_l = 0; | |
107 | + const char *fmt = "%s:" PHP_CONFIG_FILE_PATH "/%s.d"; | |
108 | char *bufpath, *debpath, *endpath; | |
109 | int lenpath; | |
110 | ||
111 | zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1); | |
112 | memset(&fh2, 0, sizeof(fh2)); | |
113 | ||
114 | - bufpath = estrdup(php_ini_scanned_path); | |
115 | + bufpath = emalloc(strlen(php_ini_scanned_path) + strlen(fmt) + strlen(sapi_module.name)); | |
116 | + sprintf(bufpath, fmt, php_ini_scanned_path, sapi_module.name); | |
117 | for (debpath = bufpath ; debpath ; debpath=endpath) { | |
118 | endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR); | |
119 | if (endpath) { | |
120 | @@ -643,7 +677,7 @@ | |
121 | } | |
122 | lenpath = (int)strlen(debpath); | |
123 | ||
124 | - if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) { | |
125 | + if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_csort)) > 0) { | |
126 | ||
127 | for (i = 0; i < ndir; i++) { | |
128 |