]> git.pld-linux.org Git - packages/php.git/blob - php-sapi-ini-file.patch
up to 7.0.0 snapshot from php-src master
[packages/php.git] / php-sapi-ini-file.patch
1 --- php-7.0/main/php_ini.c~     2015-05-21 22:56:59.000000000 +0300
2 +++ php-7.0/main/php_ini.c      2015-05-21 23:01:21.580419532 +0300
3 @@ -379,12 +379,19 @@
4  }
5  /* }}} */
6  
7 +static int php_csort(const struct dirent **a, const struct dirent **b)
8 +{
9 +       return strcmp((*a)->d_name,(*b)->d_name);
10 +}
11 +
12  /* {{{ php_init_config
13   */
14  int php_init_config(void)
15  {
16         char *php_ini_file_name = NULL;
17         char *php_ini_search_path = NULL;
18 +       // value for php_ini_loaded_file() to be stored into php_ini_opened_path
19 +       char *php_ini_loaded_file = NULL;
20         int php_ini_scanned_path_len;
21         char *open_basedir;
22         int free_ini_search_path = 0;
23 @@ -561,8 +568,29 @@
24                                 }
25                         }
26                 }
27 +               /* Search (global) php.ini file in search path */
28 +               if (!fh.handle.fp) {
29 +                       fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path TSRMLS_CC);
30 +                       if (fh.handle.fp) {
31 +                               fh.filename = php_ini_opened_path;
32 +
33 +                               // parse the ini file now
34 +                               PG(open_basedir) = open_basedir;
35 +                               fh.type = ZEND_HANDLE_FP;
36 +                               zend_parse_ini_file(&fh, 1, ZEND_INI_SCANNER_NORMAL, (zend_ini_parser_cb_t) php_ini_parser_cb, &configuration_hash TSRMLS_CC);
37 +                               open_basedir = PG(open_basedir);
38 +                               PG(open_basedir) = NULL;
39 +                               fh.handle.fp = NULL;
40  
41 -               /* Otherwise search for php-%sapi-module-name%.ini file in search path */
42 +                               // save this for later
43 +                               php_ini_loaded_file = estrdup(php_ini_opened_path);
44 +
45 +                               efree(php_ini_opened_path);
46 +                               fh.filename = php_ini_opened_path = NULL;
47 +                       }
48 +               }
49 +
50 +               /* Also search for php-%sapi-module-name%.ini file in search path */
51                 if (!fh.handle.fp) {
52                         const char *fmt = "php-%s.ini";
53                         char *ini_fname;
54 @@ -594,15 +601,12 @@
55                         if (fh.handle.fp) {
56                                 fh.filename = opened_path->val;
57                         }
58 -               }
59  
60 -               /* If still no ini file found, search for php.ini file in search path */
61 -               if (!fh.handle.fp) {
62 -                       fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
63 -                       if (fh.handle.fp) {
64 -                               fh.filename = opened_path->val;
65 -                       }
66 -               }
67 +                       // restore previous value, so php_ini_loaded_file() works as expected
68 +                       if (php_ini_loaded_file) {
69 +                               php_ini_opened_path = php_ini_loaded_file;
70 +                       }
71 +               }
72         }
73  
74         if (free_ini_search_path) {
75 @@ -597,6 +622,10 @@
76  
77                 {
78                         zval tmp;
79 +                       // use main php.ini if loaded
80 +                       if (php_ini_loaded_file) {
81 +                               fh.filename = php_ini_loaded_file;
82 +                       }
83  
84                         Z_STRLEN(tmp) = strlen(fh.filename);
85                         Z_STRVAL(tmp) = zend_strndup(fh.filename, Z_STRLEN(tmp));
86 @@ -630,13 +659,15 @@
87                 zend_llist scanned_ini_list;
88                 zend_llist_element *element;
89                 int l, total_l = 0;
90 +               const char *fmt = "%s:" PHP_CONFIG_FILE_PATH "/%s.d";
91                 char *bufpath, *debpath, *endpath;
92                 int lenpath;
93  
94                 zend_llist_init(&scanned_ini_list, sizeof(char *), (llist_dtor_func_t) free_estring, 1);
95                 memset(&fh2, 0, sizeof(fh2));
96  
97 -               bufpath = estrdup(php_ini_scanned_path);
98 +               bufpath = emalloc(strlen(php_ini_scanned_path) + strlen(fmt) + strlen(sapi_module.name));
99 +               sprintf(bufpath, fmt, php_ini_scanned_path, sapi_module.name);
100                 for (debpath = bufpath ; debpath ; debpath=endpath) {
101                         endpath = strchr(debpath, DEFAULT_DIR_SEPARATOR);
102                         if (endpath) {
103 @@ -649,7 +680,7 @@
104                         }
105                         lenpath = strlen(debpath);
106  
107 -                       if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_alphasort)) > 0) {
108 +                       if (lenpath > 0 && (ndir = php_scandir(debpath, &namelist, 0, php_csort)) > 0) {
109  
110                                 for (i = 0; i < ndir; i++) {
111  
This page took 0.029359 seconds and 3 git commands to generate.