]> git.pld-linux.org Git - packages/php.git/blame - php-sapi-ini-file.patch
updated php-sapi-ini-file.patch
[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
9b2d9fd8
ER
6--- php-7.4.0beta1.oric/main/php_ini.c 2019-07-24 12:38:41.000000000 +0300
7+++ php-7.4.0beta1/main/php_ini.c 2019-08-02 15:30:54.118722110 +0300
8@@ -410,12 +410,19 @@
9 #endif
c0240cb1 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;
9b2d9fd8 28@@ -595,21 +602,28 @@
c0240cb1 29 }
30 }
9b2d9fd8
ER
31
32- /* Otherwise search for php-%sapi-module-name%.ini file in search path */
c0240cb1 33+ /* Search (global) php.ini file in search path */
9b2d9fd8
ER
34 if (!fp) {
35- const char *fmt = "php-%s.ini";
36- char *ini_fname;
37- spprintf(&ini_fname, 0, fmt, sapi_module.name);
38- fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &opened_path);
39- efree(ini_fname);
40+ fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
41 if (fp) {
42+ zend_file_handle fh;
43 filename = ZSTR_VAL(opened_path);
44+ zend_stream_init_fp(&fh, VCWD_FOPEN(filename, "r"), filename);
45+ RESET_ACTIVE_INI_HASH();
762ec2eb 46+
9b2d9fd8 47+ zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash);
762ec2eb 48+
9b2d9fd8 49+ php_ini_loaded_file = estrdup(filename);
c0240cb1 50 }
9b2d9fd8 51 }
762ec2eb 52
c0240cb1 53- /* If still no ini file found, search for php.ini file in search path */
9b2d9fd8
ER
54+ /* Also search for php-%sapi-module-name%.ini file in search path */
55 if (!fp) {
56- fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
57+ const char *fmt = "php-%s.ini";
58+ char *ini_fname;
59+ spprintf(&ini_fname, 0, fmt, sapi_module.name);
60+ fp = php_fopen_with_path(ini_fname, "r", php_ini_search_path, &opened_path);
61+ efree(ini_fname);
62 if (fp) {
63 filename = ZSTR_VAL(opened_path);
64 }
65@@ -631,14 +645,28 @@
762ec2eb
ER
66
67 {
68 zval tmp;
69+ // use main php.ini if loaded
b002612e
ER
70+ // see https://github.com/pld-linux/php/commit/762ec2e
71+ // test with:
72+ // php -r 'var_dump(array(get_cfg_var("cfg_file_path"),php_ini_loaded_file()));'
762ec2eb 73+ if (php_ini_loaded_file) {
b002612e
ER
74+ if (fh.filename) {
75+ efree((char *)fh.filename);
76+ }
762ec2eb
ER
77+ fh.filename = php_ini_loaded_file;
78+ }
c0240cb1 79
b002612e
ER
80 ZVAL_NEW_STR(&tmp, zend_string_init(fh.filename, strlen(fh.filename), 1));
81 zend_hash_str_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path")-1, &tmp);
82 if (opened_path) {
bc0e70fe 83 zend_string_release_ex(opened_path, 0);
b002612e
ER
84- } else {
85+ }
86+
87+ if (fh.filename) {
88 efree((char *)fh.filename);
89+ fh.filename = NULL;
90 }
91+
92 php_ini_opened_path = zend_strndup(Z_STRVAL(tmp), Z_STRLEN(tmp));
93 }
94 }
9b2d9fd8 95@@ -661,12 +689,14 @@
c0240cb1 96 zend_llist scanned_ini_list;
97 zend_llist_element *element;
98 int l, total_l = 0;
99+ const char *fmt = "%s:" PHP_CONFIG_FILE_PATH "/%s.d";
2e0e7ed6
AM
100 char *bufpath, *debpath, *endpath;
101 int lenpath;
c0240cb1 102
c0240cb1 103 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
b4025702 104
2e0e7ed6
AM
105- bufpath = estrdup(php_ini_scanned_path);
106+ bufpath = emalloc(strlen(php_ini_scanned_path) + strlen(fmt) + strlen(sapi_module.name));
107+ sprintf(bufpath, fmt, php_ini_scanned_path, sapi_module.name);
108 for (debpath = bufpath ; debpath ; debpath=endpath) {
109 endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR);
110 if (endpath) {
9b2d9fd8 111@@ -679,7 +709,7 @@
2e0e7ed6 112 }
b002612e 113 lenpath = (int)strlen(debpath);
c0240cb1 114
2e0e7ed6
AM
115- if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) {
116+ if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_csort)) > 0) {
c0240cb1 117
118 for (i = 0; i < ndir; i++) {
2e0e7ed6 119
This page took 0.189509 seconds and 4 git commands to generate.