Commit 3a1e8848 authored by rswindell's avatar rswindell
Browse files

CGI optimization: don't re-read the ctrl/cgi_env.ini file for each request

(just upon [re]init). The cgi_env.ini file is now monitored to force recycle.
Removed hard-coded CGI environment kludge for PHP-CGI and moved to default
ctrl/cgi_env.ini. If you're using PHP-CGI, you'll want to add the following to
your cgi_env.ini file:
[REDIRECT_STATUS]
value=200
parent 824a8623
......@@ -118,6 +118,7 @@ static web_startup_t* startup=NULL;
static js_server_props_t js_server_props;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
static str_list_t cgi_env;
static ulong session_threads=0;
static named_string_t** mime_types;
......@@ -3150,7 +3151,6 @@ static str_list_t get_cgi_env(http_session_t *session)
char append[INI_MAX_VALUE_LEN+1];
char prepend[INI_MAX_VALUE_LEN+1];
char env_str[(INI_MAX_VALUE_LEN*4)+2];
FILE* fp;
size_t i;
str_list_t env_list;
str_list_t add_list;
......@@ -3161,21 +3161,16 @@ static str_list_t get_cgi_env(http_session_t *session)
strListAppendList(&env_list, session->req.cgi_env);
strListPush(&env_list,"REDIRECT_STATUS=200"); /* Kludge for php-cgi */
if((fp=iniOpenFile(cgi_env_ini,/* create? */FALSE))==NULL)
return(env_list);
/* FREE()d in this block */
if((add_list=iniReadSectionList(fp,NULL))!=NULL) {
if((add_list=iniGetSectionList(cgi_env,NULL))!=NULL) {
for(i=0; add_list[i]!=NULL; i++) {
if((deflt=getenv(add_list[i]))==NULL)
deflt=iniReadString(fp,add_list[i],"default",NULL,defltbuf);
if(iniReadString(fp,add_list[i],"value",deflt,value)==NULL)
deflt=iniGetString(cgi_env,add_list[i],"default",NULL,defltbuf);
if(iniGetString(cgi_env,add_list[i],"value",deflt,value)==NULL)
continue;
iniReadString(fp,add_list[i],"append","",append);
iniReadString(fp,add_list[i],"prepend","",prepend);
iniGetString(cgi_env,add_list[i],"append","",append);
iniGetString(cgi_env,add_list[i],"prepend","",prepend);
safe_snprintf(env_str,sizeof(env_str),"%s=%s%s%s"
,add_list[i], prepend, value, append);
strListPush(&env_list,env_str);
......@@ -3183,8 +3178,6 @@ static str_list_t get_cgi_env(http_session_t *session)
iniFreeStringList(add_list);
}
fclose(fp);
return(env_list);
}
......@@ -5161,6 +5154,8 @@ static void cleanup(int code)
cgi_handlers=iniFreeNamedStringList(cgi_handlers);
xjs_handlers=iniFreeNamedStringList(xjs_handlers);
cgi_env=iniFreeStringList(cgi_env);
semfile_list_free(&recycle_semfiles);
semfile_list_free(&shutdown_semfiles);
......@@ -5333,6 +5328,7 @@ void DLLCALL web_server(void* arg)
fd_set socket_set;
time_t t;
time_t initialized=0;
FILE* fp;
char* p;
char compiler[32];
http_session_t * session=NULL;
......@@ -5484,6 +5480,10 @@ void DLLCALL web_server(void* arg)
/* Don't do this for *each* CGI request, just once here during [re]init */
iniFileName(cgi_env_ini,sizeof(cgi_env_ini),scfg.ctrl_dir,"cgi_env.ini");
if((fp=iniOpenFile(cgi_env_ini,/* create? */FALSE)) != NULL) {
cgi_env = iniReadFile(fp);
iniCloseFile(fp);
}
if(startup->host_name[0]==0)
SAFECOPY(startup->host_name,scfg.sys_inetaddr);
......@@ -5585,6 +5585,7 @@ void DLLCALL web_server(void* arg)
semfile_list_add(&recycle_semfiles,path);
semfile_list_add(&recycle_semfiles,mime_types_ini);
semfile_list_add(&recycle_semfiles,web_handler_ini);
semfile_list_add(&recycle_semfiles,cgi_env_ini);
if(!initialized) {
initialized=time(NULL);
semfile_list_check(&initialized,recycle_semfiles);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment