]> git.pld-linux.org Git - packages/php.git/blame - php-sapi-ini-file.patch
up to 7.4.0alpha3
[packages/php.git] / php-sapi-ini-file.patch
CommitLineData
b002612e
ER
1to test which is main php.ini:
2$ php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));'
3
4https://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 @@
c0240cb1 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 */
f4ee12ea 19 int php_init_config(void)
762ec2eb
ER
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;
b002612e 28@@ -557,8 +564,26 @@
c0240cb1 29 }
30 }
31 }
32+ /* Search (global) php.ini file in search path */
33+ if (!fh.handle.fp) {
b002612e 34+ fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
c0240cb1 35+ if (fh.handle.fp) {
b002612e 36+ fh.filename = ZSTR_VAL(opened_path);
762ec2eb
ER
37+
38+ // parse the ini file now
c0240cb1 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);
c0240cb1 42+ open_basedir = PG(open_basedir);
c0240cb1 43+ PG(open_basedir) = NULL;
44+ fh.handle.fp = NULL;
762ec2eb 45+
b002612e
ER
46+ php_ini_loaded_file = estrdup(fh.filename);
47+ fh.filename = NULL;
c0240cb1 48+ }
49+ }
b002612e
ER
50
51- /* Otherwise search for php-%sapi-module-name%.ini file in search path */
762ec2eb 52+ /* Also search for php-%sapi-module-name%.ini file in search path */
c0240cb1 53 if (!fh.handle.fp) {
762ec2eb
ER
54 const char *fmt = "php-%s.ini";
55 char *ini_fname;
b002612e 56@@ -568,15 +593,8 @@
762ec2eb 57 if (fh.handle.fp) {
00938eac 58 fh.filename = ZSTR_VAL(opened_path);
c0240cb1 59 }
762ec2eb
ER
60- }
61
c0240cb1 62- /* If still no ini file found, search for php.ini file in search path */
63- if (!fh.handle.fp) {
f4ee12ea 64- fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
c0240cb1 65- if (fh.handle.fp) {
00938eac 66- fh.filename = ZSTR_VAL(opened_path);
f4ee12ea
ER
67- }
68- }
f4ee12ea 69+ }
c0240cb1 70 }
f4ee12ea
ER
71
72 if (free_ini_search_path) {
b002612e 73@@ -593,14 +611,28 @@
762ec2eb
ER
74
75 {
76 zval tmp;
77+ // use main php.ini if loaded
b002612e
ER
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()));'
762ec2eb 81+ if (php_ini_loaded_file) {
b002612e
ER
82+ if (fh.filename) {
83+ efree((char *)fh.filename);
84+ }
762ec2eb
ER
85+ fh.filename = php_ini_loaded_file;
86+ }
c0240cb1 87
b002612e
ER
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) {
bc0e70fe 91 zend_string_release_ex(opened_path, 0);
b002612e
ER
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 @@
c0240cb1 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";
2e0e7ed6
AM
108 char *bufpath, *debpath, *endpath;
109 int lenpath;
c0240cb1 110
c0240cb1 111 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
2e0e7ed6 112 memset(&fh2, 0, sizeof(fh2));
b4025702 113
2e0e7ed6
AM
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) {
b002612e 120@@ -643,7 +677,7 @@
2e0e7ed6 121 }
b002612e 122 lenpath = (int)strlen(debpath);
c0240cb1 123
2e0e7ed6
AM
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) {
c0240cb1 126
127 for (i = 0; i < ndir; i++) {
2e0e7ed6 128
This page took 0.130992 seconds and 4 git commands to generate.