Skip to content

Commit bd0ac7f

Browse files
committed
Many patches. I hope I remember them all:
- Make sapi_module available to external modules (PHPAPI) - Make the php.ini path reported in phpinfo() always point to real full path of the php.ini file - Optimized the ISAPI module not to read unnecessary server variables and read necessary variables at most once.
1 parent 348f6c6 commit bd0ac7f

File tree

19 files changed

+280
-250
lines changed

19 files changed

+280
-250
lines changed

Diff for: NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP 4.0 NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33

44
?? ??? 200?, Version 4.0.5
5+
- Made the php.ini path reported in phpinfo() always point to the absolute
6+
path that was opened (Zeev)
7+
- Made the INI mechanism thread safe (Zeev, Zend engine)
58
- Changed setlocale() to use LC_* constants. (Jani)
69
- ctype functions now follow the extension naming conventions (Hartmut)
710
- Added iconv() function (using libc or libiconv) (Stig)

Diff for: ext/standard/info.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#define SECTION(name) PUTS("<H2 align=\"center\">" name "</H2>\n")
4141

42-
PHPAPI extern char *php_ini_path;
42+
PHPAPI extern char *php_ini_opened_path;
4343

4444
static int _display_module_info(zend_module_entry *module, void *arg)
4545
{
@@ -197,7 +197,7 @@ PHPAPI void php_print_info(int flag)
197197
php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
198198
#endif
199199

200-
php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_path?php_ini_path:CONFIGURATION_FILE_PATH );
200+
php_info_print_table_row(2, "Configuration File (php.ini) Path", php_ini_opened_path?php_ini_opened_path:CONFIGURATION_FILE_PATH);
201201

202202
#if ZEND_DEBUG
203203
php_info_print_table_row(2, "ZEND_DEBUG", "enabled" );

Diff for: main/SAPI.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void sapi_globals_ctor(sapi_globals_struct *sapi_globals)
5454
}
5555

5656
/* True globals (no need for thread safety) */
57-
sapi_module_struct sapi_module;
57+
SAPI_API sapi_module_struct sapi_module;
5858
SAPI_API void (*sapi_error)(int error_type, const char *message, ...);
5959

6060

Diff for: main/SAPI.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ typedef struct _sapi_post_entry sapi_post_entry;
5757
typedef struct _sapi_module_struct sapi_module_struct;
5858

5959

60-
extern sapi_module_struct sapi_module; /* true global */
60+
extern SAPI_API sapi_module_struct sapi_module; /* true global */
6161

6262
/* Some values in this structure needs to be filled in before
6363
* calling sapi_activate(). We WILL change the `char *' entries,
@@ -188,6 +188,8 @@ struct _sapi_module_struct {
188188
void (*register_server_variables)(zval *track_vars_array ELS_DC SLS_DC PLS_DC);
189189
void (*log_message)(char *message);
190190

191+
char *php_ini_path_override;
192+
191193
void (*block_interruptions)(void);
192194
void (*unblock_interruptions)(void);
193195

@@ -222,7 +224,7 @@ struct _sapi_post_entry {
222224
SAPI_POST_READER_FUNC(sapi_read_standard_form_data);
223225
SAPI_POST_READER_FUNC(php_default_post_reader);
224226

225-
#define STANDARD_SAPI_MODULE_PROPERTIES NULL
227+
#define STANDARD_SAPI_MODULE_PROPERTIES NULL, NULL
226228

227229
#endif /* SAPI_H */
228230

Diff for: main/main.c

+1-12
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ void *gLock; /*mutex variable */
106106

107107
/* True globals (no need for thread safety) */
108108
HashTable configuration_hash;
109-
PHPAPI char *php_ini_path = NULL;
110-
111109

112110
#define SAFE_FILENAME(f) ((f)?(f):"-")
113111

@@ -700,15 +698,6 @@ void php_request_shutdown(void *dummy)
700698
}
701699
}
702700

703-
704-
static int php_config_ini_startup(void)
705-
{
706-
if (php_init_config() == FAILURE) {
707-
php_printf("PHP: Unable to parse configuration file.\n");
708-
return FAILURE;
709-
}
710-
return SUCCESS;
711-
}
712701

713702
static void php_config_ini_shutdown(void)
714703
{
@@ -860,7 +849,7 @@ int php_module_startup(sapi_module_struct *sf)
860849
le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
861850
FREE_MUTEX(gLock);
862851

863-
if (php_config_ini_startup() == FAILURE) {
852+
if (php_init_config(sf->php_ini_path_override) == FAILURE) {
864853
return FAILURE;
865854
}
866855

Diff for: main/php_ini.c

+62-75
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
#include "ext/standard/dl.h"
2525
#include "zend_extensions.h"
2626

27+
/* True globals */
2728
static HashTable configuration_hash;
28-
PHPAPI extern char *php_ini_path;
29+
PHPAPI char *php_ini_opened_path=NULL;
2930

3031

3132
static void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type)
@@ -145,96 +146,79 @@ static void php_config_ini_parser_cb(zval *arg1, zval *arg2, int callback_type,
145146
}
146147

147148

148-
int php_init_config(void)
149+
int php_init_config(char *php_ini_path_override)
149150
{
151+
char *env_location, *php_ini_search_path;
152+
int safe_mode_state;
153+
char *open_basedir;
154+
int free_ini_search_path=0;
155+
zend_file_handle fh;
150156
PLS_FETCH();
151157

152158
if (zend_hash_init(&configuration_hash, 0, NULL, (dtor_func_t) pvalue_config_destructor, 1)==FAILURE) {
153159
return FAILURE;
154160
}
155161

156-
#if USE_CONFIG_FILE
157-
{
158-
char *env_location,*default_location,*php_ini_search_path;
159-
int safe_mode_state = PG(safe_mode);
160-
char *open_basedir = PG(open_basedir);
161-
char *opened_path;
162-
int free_default_location=0;
163-
zend_file_handle fh;
164-
165-
env_location = getenv("PHPRC");
166-
if (!env_location) {
167-
env_location="";
168-
}
169-
#ifdef PHP_WIN32
170-
{
171-
if (php_ini_path) {
172-
default_location = php_ini_path;
173-
} else {
174-
default_location = (char *) malloc(512);
175-
176-
if (!GetWindowsDirectory(default_location,255)) {
177-
default_location[0]=0;
178-
}
179-
free_default_location=1;
180-
}
181-
}
182-
#else
183-
if (!php_ini_path) {
184-
default_location = CONFIGURATION_FILE_PATH;
185-
} else {
186-
default_location = php_ini_path;
187-
}
188-
#endif
162+
safe_mode_state = PG(safe_mode);
163+
open_basedir = PG(open_basedir);
189164

190-
/* build a path */
191-
php_ini_search_path = (char *) malloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
165+
env_location = getenv("PHPRC");
166+
if (!env_location) {
167+
env_location="";
168+
}
169+
if (php_ini_path_override) {
170+
php_ini_search_path = php_ini_path_override;
171+
free_ini_search_path = 0;
172+
} else {
173+
char *default_location;
174+
int free_default_location;
192175

193-
if (!php_ini_path) {
194176
#ifdef PHP_WIN32
195-
sprintf(php_ini_search_path,".;%s;%s",env_location,default_location);
177+
default_location = (char *) emalloc(512);
178+
179+
if (!GetWindowsDirectory(default_location,255)) {
180+
default_location[0]=0;
181+
}
182+
free_default_location=1;
196183
#else
197-
sprintf(php_ini_search_path,".:%s:%s",env_location,default_location);
184+
default_location = CONFIGURATION_FILE_PATH;
185+
free_default_location=0;
198186
#endif
199-
} else {
200-
/* if path was set via -c flag, only look there */
201-
strcpy(php_ini_search_path,default_location);
202-
}
203-
PG(safe_mode) = 0;
204-
PG(open_basedir) = NULL;
205-
206-
207-
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &opened_path);
208-
free(php_ini_search_path);
187+
php_ini_search_path = (char *) emalloc(sizeof(".")+strlen(env_location)+strlen(default_location)+2+1);
188+
free_ini_search_path = 1;
189+
sprintf(php_ini_search_path, ".%c%s%c%s", ZEND_PATHS_SEPARATOR, env_location, ZEND_PATHS_SEPARATOR, default_location);
209190
if (free_default_location) {
210-
free(default_location);
211-
}
212-
PG(safe_mode) = safe_mode_state;
213-
PG(open_basedir) = open_basedir;
214-
215-
if (!fh.handle.fp) {
216-
return SUCCESS; /* having no configuration file is ok */
217-
}
218-
fh.type = ZEND_HANDLE_FP;
219-
fh.filename = opened_path;
220-
221-
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, NULL);
222-
223-
if (opened_path) {
224-
zval tmp;
225-
226-
tmp.value.str.val = strdup(opened_path);
227-
tmp.value.str.len = strlen(opened_path);
228-
tmp.type = IS_STRING;
229-
zend_hash_update(&configuration_hash,"cfg_file_path",sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval),NULL);
230-
#if DEBUG_CFG_PARSER
231-
php_printf("INI file opened at '%s'\n",opened_path);
232-
#endif
233-
efree(opened_path);
191+
efree(default_location);
234192
}
235193
}
194+
195+
PG(safe_mode) = 0;
196+
PG(open_basedir) = NULL;
236197

237-
#endif
198+
fh.handle.fp = php_fopen_with_path("php.ini", "r", php_ini_search_path, &php_ini_opened_path);
199+
if (free_ini_search_path) {
200+
efree(php_ini_search_path);
201+
}
202+
PG(safe_mode) = safe_mode_state;
203+
PG(open_basedir) = open_basedir;
204+
205+
if (!fh.handle.fp) {
206+
return SUCCESS; /* having no configuration file is ok */
207+
}
208+
fh.type = ZEND_HANDLE_FP;
209+
fh.filename = php_ini_opened_path;
210+
211+
zend_parse_ini_file(&fh, 1, php_config_ini_parser_cb, NULL);
212+
213+
if (php_ini_opened_path) {
214+
zval tmp;
215+
216+
tmp.value.str.len = strlen(php_ini_opened_path);
217+
tmp.value.str.val = zend_strndup(php_ini_opened_path, tmp.value.str.len);
218+
tmp.type = IS_STRING;
219+
zend_hash_update(&configuration_hash, "cfg_file_path", sizeof("cfg_file_path"),(void *) &tmp,sizeof(zval), NULL);
220+
persist_alloc(php_ini_opened_path);
221+
}
238222

239223
return SUCCESS;
240224
}
@@ -243,6 +227,9 @@ int php_init_config(void)
243227
int php_shutdown_config(void)
244228
{
245229
zend_hash_destroy(&configuration_hash);
230+
if (php_ini_opened_path) {
231+
efree(php_ini_opened_path);
232+
}
246233
return SUCCESS;
247234
}
248235

Diff for: main/php_ini.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "zend_ini.h"
2323

24-
int php_init_config(void);
24+
int php_init_config(char *php_ini_path_override);
2525
int php_shutdown_config(void);
2626

2727
#define PHP_INI_USER ZEND_INI_USER

Diff for: sapi/aolserver/aolserver.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ php_ns_sapi_register_variables(zval *track_vars_array ELS_DC SLS_DC PLS_DC)
368368

369369
/* this structure is static (as in "it does not change") */
370370

371-
static sapi_module_struct sapi_module = {
371+
static sapi_module_struct aolserver_sapi_module = {
372372
"aolserver",
373373
"AOLserver",
374374

@@ -606,15 +606,15 @@ int Ns_ModuleInit(char *server, char *module)
606606
php_ns_context *ctx;
607607

608608
tsrm_startup(1, 1, 0, NULL);
609-
sapi_startup(&sapi_module);
610-
sapi_module.startup(&sapi_module);
609+
sapi_startup(&aolserver_sapi_module);
610+
sapi_module.startup(&aolserver_sapi_module);
611611

612612
/* TSRM is used to allocate a per-thread structure */
613613
ns_globals_id = ts_allocate_id(sizeof(ns_globals_struct), NULL, NULL);
614614

615615
/* the context contains data valid for all threads */
616616
ctx = malloc(sizeof *ctx);
617-
ctx->sapi_module = &sapi_module;
617+
ctx->sapi_module = &aolserver_sapi_module;
618618
ctx->ns_server = strdup(server);
619619
ctx->ns_module = strdup(module);
620620

Diff for: sapi/apache/mod_php4.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static void sapi_apache_register_server_variables(zval *track_vars_array ELS_DC
249249

250250
static int php_apache_startup(sapi_module_struct *sapi_module)
251251
{
252-
if(php_module_startup(sapi_module) == FAILURE
252+
if(php_module_startup(sapi_module, NULL) == FAILURE
253253
|| zend_startup_module(&apache_module_entry) == FAILURE) {
254254
return FAILURE;
255255
} else {
@@ -320,7 +320,7 @@ static char *php_apache_getenv(char *name, size_t name_len SLS_DC)
320320
}
321321

322322

323-
static sapi_module_struct sapi_module_conf = {
323+
static sapi_module_struct apache_sapi_module = {
324324
"apache", /* name */
325325
"Apache", /* pretty name */
326326

@@ -590,8 +590,8 @@ CONST_PREFIX char *php_apache_value_handler_ex(cmd_parms *cmd, HashTable *conf,
590590
#ifdef ZTS
591591
tsrm_startup(1, 1, 0, NULL);
592592
#endif
593-
sapi_startup(&sapi_module_conf);
594-
php_apache_startup(&sapi_module_conf);
593+
sapi_startup(&apache_sapi_module);
594+
php_apache_startup(&apache_sapi_module);
595595
}
596596
per_dir_entry.type = mode;
597597

@@ -675,7 +675,7 @@ int php_xbithack_handler(request_rec * r)
675675
static void apache_php_module_shutdown_wrapper(void)
676676
{
677677
apache_php_initialized = 0;
678-
sapi_module_conf.shutdown(&sapi_module_conf);
678+
apache_sapi_module.shutdown(&apache_sapi_module);
679679

680680
#if MODULE_MAGIC_NUMBER >= 19970728
681681
/* This function is only called on server exit if the apache API
@@ -693,7 +693,7 @@ static void apache_php_module_shutdown_wrapper(void)
693693
static void php_child_exit_handler(server_rec *s, pool *p)
694694
{
695695
/* apache_php_initialized = 0; */
696-
sapi_module_conf.shutdown(&sapi_module_conf);
696+
apache_sapi_module.shutdown(&apache_sapi_module);
697697

698698
#ifdef ZTS
699699
tsrm_shutdown();
@@ -709,8 +709,8 @@ void php_init_handler(server_rec *s, pool *p)
709709
#ifdef ZTS
710710
tsrm_startup(1, 1, 0, NULL);
711711
#endif
712-
sapi_startup(&sapi_module_conf);
713-
php_apache_startup(&sapi_module_conf);
712+
sapi_startup(&apache_sapi_module);
713+
php_apache_startup(&apache_sapi_module);
714714
}
715715
#if MODULE_MAGIC_NUMBER >= 19980527
716716
{

Diff for: sapi/apache2filter/sapi_apache2.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static void php_apache_sapi_log_message(char *msg)
187187
apr_puts(msg, ctx->f->r->server->error_log);
188188
}
189189

190-
static sapi_module_struct sapi_module = {
190+
static sapi_module_struct apache2_sapi_module = {
191191
"apache2filter",
192192
"Apache 2.0 Filter",
193193

@@ -420,7 +420,7 @@ static int php_output_filter(ap_filter_t *f, ap_bucket_brigade *bb)
420420
static apr_status_t
421421
php_apache_server_shutdown(void *tmp)
422422
{
423-
sapi_module.shutdown(&sapi_module);
423+
apache2_sapi_module.shutdown(&apache2_sapi_module);
424424
sapi_shutdown();
425425
tsrm_shutdown();
426426
return APR_SUCCESS;
@@ -430,8 +430,8 @@ static void
430430
php_apache_server_startup(apr_pool_t *pchild, server_rec *s)
431431
{
432432
tsrm_startup(1, 1, 0, NULL);
433-
sapi_startup(&sapi_module);
434-
sapi_module.startup(&sapi_module);
433+
sapi_startup(&apache1_sapi_module);
434+
apache2_sapi_module.startup(&apache2_sapi_module);
435435
apr_register_cleanup(pchild, NULL, php_apache_server_shutdown, NULL);
436436
php_apache_register_module();
437437
}

0 commit comments

Comments
 (0)