You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ch...@apache.org on 2009/03/18 17:37:32 UTC
svn commit: r755634 [5/6] - in /httpd/mod_fcgid/trunk/mod_fcgid: ./
arch/unix/ arch/win32/
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_pm_main.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_pm_main.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_pm_main.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_pm_main.c Wed Mar 18 16:37:31 2009
@@ -33,482 +33,482 @@
static void
link_node_to_list(server_rec * main_server,
- fcgid_procnode * header,
- fcgid_procnode * node, fcgid_procnode * table_array)
+ fcgid_procnode * header,
+ fcgid_procnode * node, fcgid_procnode * table_array)
{
- safe_lock(main_server);
- node->next_index = header->next_index;
- header->next_index = node - table_array;
- safe_unlock(main_server);
+ safe_lock(main_server);
+ node->next_index = header->next_index;
+ header->next_index = node - table_array;
+ safe_unlock(main_server);
}
static apr_time_t lastidlescan = 0;
static void scan_idlelist(server_rec * main_server)
{
- /*
- Scan the idle list
- 1. move all processes idle timeout to error list
- 2. move all processes lifetime expired to error list
- */
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *error_list_header;
- fcgid_procnode *proc_table;
- apr_time_t last_active_time, start_time;
- apr_time_t now = apr_time_now();
-
- /* Should I check the idle list now? */
- if (procmgr_must_exit()
- || apr_time_sec(now) - apr_time_sec(lastidlescan) <=
- g_idle_scan_interval)
- return;
- lastidlescan = now;
-
- /* Check the list */
- proc_table = proctable_get_table_array();
- previous_node = proctable_get_idle_list();
- error_list_header = proctable_get_error_list();
-
- safe_lock(main_server);
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
- last_active_time = current_node->last_active_time;
- start_time = current_node->start_time;
- if ((apr_time_sec(now) - apr_time_sec(last_active_time) >
- g_idle_timeout
- || apr_time_sec(now) - apr_time_sec(start_time) >
- g_proc_lifetime)
- && is_kill_allowed(current_node)) {
- /* Set die reason for log */
- if (apr_time_sec(now) - apr_time_sec(last_active_time) >
- g_idle_timeout)
- current_node->diewhy = FCGID_DIE_IDLE_TIMEOUT;
- else if (apr_time_sec(now) - apr_time_sec(start_time) >
- g_proc_lifetime)
- current_node->diewhy = FCGID_DIE_LIFETIME_EXPIRED;
-
- /* Unlink from idle list */
- previous_node->next_index = current_node->next_index;
-
- /* Link to error list */
- current_node->next_index = error_list_header->next_index;
- error_list_header->next_index = current_node - proc_table;
- } else
- previous_node = current_node;
-
- current_node = next_node;
- }
- safe_unlock(main_server);
+ /*
+ Scan the idle list
+ 1. move all processes idle timeout to error list
+ 2. move all processes lifetime expired to error list
+ */
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *error_list_header;
+ fcgid_procnode *proc_table;
+ apr_time_t last_active_time, start_time;
+ apr_time_t now = apr_time_now();
+
+ /* Should I check the idle list now? */
+ if (procmgr_must_exit()
+ || apr_time_sec(now) - apr_time_sec(lastidlescan) <=
+ g_idle_scan_interval)
+ return;
+ lastidlescan = now;
+
+ /* Check the list */
+ proc_table = proctable_get_table_array();
+ previous_node = proctable_get_idle_list();
+ error_list_header = proctable_get_error_list();
+
+ safe_lock(main_server);
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+ last_active_time = current_node->last_active_time;
+ start_time = current_node->start_time;
+ if ((apr_time_sec(now) - apr_time_sec(last_active_time) >
+ g_idle_timeout
+ || apr_time_sec(now) - apr_time_sec(start_time) >
+ g_proc_lifetime)
+ && is_kill_allowed(current_node)) {
+ /* Set die reason for log */
+ if (apr_time_sec(now) - apr_time_sec(last_active_time) >
+ g_idle_timeout)
+ current_node->diewhy = FCGID_DIE_IDLE_TIMEOUT;
+ else if (apr_time_sec(now) - apr_time_sec(start_time) >
+ g_proc_lifetime)
+ current_node->diewhy = FCGID_DIE_LIFETIME_EXPIRED;
+
+ /* Unlink from idle list */
+ previous_node->next_index = current_node->next_index;
+
+ /* Link to error list */
+ current_node->next_index = error_list_header->next_index;
+ error_list_header->next_index = current_node - proc_table;
+ } else
+ previous_node = current_node;
+
+ current_node = next_node;
+ }
+ safe_unlock(main_server);
}
static apr_time_t lastbusyscan = 0;
static void scan_busylist(server_rec * main_server)
{
- /*
- Scan the busy list
- 1. move all expired node to error list
- */
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *error_list_header;
- fcgid_procnode *proc_table;
- apr_time_t last_active_time;
- apr_time_t now = apr_time_now();
-
- /* Should I check the busy list? */
- if (procmgr_must_exit()
- || apr_time_sec(now) - apr_time_sec(lastbusyscan) <=
- g_busy_scan_interval)
- return;
- lastbusyscan = now;
-
- /* Check the list */
- proc_table = proctable_get_table_array();
- previous_node = proctable_get_busy_list();
- error_list_header = proctable_get_error_list();
-
- safe_lock(main_server);
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
-
- last_active_time = current_node->last_active_time;
- if (apr_time_sec(now) - apr_time_sec(last_active_time) >
- g_busy_timeout) {
- /* Set dir reason for log */
- current_node->diewhy = FCGID_DIE_BUSY_TIMEOUT;
-
- /* Unlink from busy list */
- previous_node->next_index = current_node->next_index;
-
- /* Link to error list */
- current_node->next_index = error_list_header->next_index;
- error_list_header->next_index = current_node - proc_table;
- } else
- previous_node = current_node;
-
- current_node = next_node;
- }
- safe_unlock(main_server);
+ /*
+ Scan the busy list
+ 1. move all expired node to error list
+ */
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *error_list_header;
+ fcgid_procnode *proc_table;
+ apr_time_t last_active_time;
+ apr_time_t now = apr_time_now();
+
+ /* Should I check the busy list? */
+ if (procmgr_must_exit()
+ || apr_time_sec(now) - apr_time_sec(lastbusyscan) <=
+ g_busy_scan_interval)
+ return;
+ lastbusyscan = now;
+
+ /* Check the list */
+ proc_table = proctable_get_table_array();
+ previous_node = proctable_get_busy_list();
+ error_list_header = proctable_get_error_list();
+
+ safe_lock(main_server);
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+
+ last_active_time = current_node->last_active_time;
+ if (apr_time_sec(now) - apr_time_sec(last_active_time) >
+ g_busy_timeout) {
+ /* Set dir reason for log */
+ current_node->diewhy = FCGID_DIE_BUSY_TIMEOUT;
+
+ /* Unlink from busy list */
+ previous_node->next_index = current_node->next_index;
+
+ /* Link to error list */
+ current_node->next_index = error_list_header->next_index;
+ error_list_header->next_index = current_node - proc_table;
+ } else
+ previous_node = current_node;
+
+ current_node = next_node;
+ }
+ safe_unlock(main_server);
}
static apr_time_t lastzombiescan = 0;
static void scan_idlelist_zombie(server_rec * main_server)
{
- /*
- Scan the idle list
- 1. pick up the node for scan(now-last_activ>g_zombie_scan_interval)
- 2. check if it's zombie process
- 3. if it's zombie process, wait() and return to free list
- 4. return to idle list if it's not zombie process
- */
- pid_t thepid;
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *error_list_header, *check_list_header;
- fcgid_procnode *proc_table;
- apr_time_t last_active_time;
- apr_time_t now = apr_time_now();
- fcgid_procnode temp_header;
-
- memset(&temp_header, 0, sizeof(temp_header));
-
- /* Should I check zombie processes in idle list now? */
- if (procmgr_must_exit()
- || apr_time_sec(now) - apr_time_sec(lastzombiescan) <=
- g_zombie_scan_interval)
- return;
- lastzombiescan = now;
-
- /*
- Check the list
- */
- proc_table = proctable_get_table_array();
- previous_node = proctable_get_idle_list();
- error_list_header = proctable_get_error_list();
- check_list_header = &temp_header;
-
- safe_lock(main_server);
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
-
- /* Is it time for zombie check? */
- last_active_time = current_node->last_active_time;
- if (apr_time_sec(now) - apr_time_sec(last_active_time) >
- g_zombie_scan_interval) {
- /* Unlink from idle list */
- previous_node->next_index = current_node->next_index;
-
- /* Link to check list */
- current_node->next_index = check_list_header->next_index;
- check_list_header->next_index = current_node - proc_table;
- } else
- previous_node = current_node;
-
- current_node = next_node;
- }
- safe_unlock(main_server);
-
- /*
- Now check every node in check list
- 1) If it's zombie process, wait() and return to free list
- 2) If it's not zombie process, link it to the tail of idle list
- */
- previous_node = check_list_header;
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
-
- /* Is it zombie process? */
- thepid = current_node->proc_id->pid;
- if (proc_wait_process(main_server, current_node) == APR_CHILD_DONE) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: cleanup zombie process %"
- APR_PID_T_FMT, thepid);
-
- /* Unlink from check list */
- previous_node->next_index = current_node->next_index;
-
- /* Link to free list */
- link_node_to_list(main_server, proctable_get_free_list(),
- current_node, proc_table);
- } else
- previous_node = current_node;
-
- current_node = next_node;
- }
-
- /*
- Now link the check list back to the tail of idle list
- */
- if (check_list_header->next_index) {
- safe_lock(main_server);
- previous_node = proctable_get_idle_list();
- current_node = &proc_table[previous_node->next_index];
-
- /* Find the tail of idle list */
- while (current_node != proc_table) {
- previous_node = current_node;
- current_node = &proc_table[current_node->next_index];
- }
-
- /* Link check list to the tail of idle list */
- previous_node->next_index = check_list_header->next_index;
- safe_unlock(main_server);
- }
+ /*
+ Scan the idle list
+ 1. pick up the node for scan(now-last_activ>g_zombie_scan_interval)
+ 2. check if it's zombie process
+ 3. if it's zombie process, wait() and return to free list
+ 4. return to idle list if it's not zombie process
+ */
+ pid_t thepid;
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *error_list_header, *check_list_header;
+ fcgid_procnode *proc_table;
+ apr_time_t last_active_time;
+ apr_time_t now = apr_time_now();
+ fcgid_procnode temp_header;
+
+ memset(&temp_header, 0, sizeof(temp_header));
+
+ /* Should I check zombie processes in idle list now? */
+ if (procmgr_must_exit()
+ || apr_time_sec(now) - apr_time_sec(lastzombiescan) <=
+ g_zombie_scan_interval)
+ return;
+ lastzombiescan = now;
+
+ /*
+ Check the list
+ */
+ proc_table = proctable_get_table_array();
+ previous_node = proctable_get_idle_list();
+ error_list_header = proctable_get_error_list();
+ check_list_header = &temp_header;
+
+ safe_lock(main_server);
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+
+ /* Is it time for zombie check? */
+ last_active_time = current_node->last_active_time;
+ if (apr_time_sec(now) - apr_time_sec(last_active_time) >
+ g_zombie_scan_interval) {
+ /* Unlink from idle list */
+ previous_node->next_index = current_node->next_index;
+
+ /* Link to check list */
+ current_node->next_index = check_list_header->next_index;
+ check_list_header->next_index = current_node - proc_table;
+ } else
+ previous_node = current_node;
+
+ current_node = next_node;
+ }
+ safe_unlock(main_server);
+
+ /*
+ Now check every node in check list
+ 1) If it's zombie process, wait() and return to free list
+ 2) If it's not zombie process, link it to the tail of idle list
+ */
+ previous_node = check_list_header;
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+
+ /* Is it zombie process? */
+ thepid = current_node->proc_id->pid;
+ if (proc_wait_process(main_server, current_node) == APR_CHILD_DONE) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: cleanup zombie process %"
+ APR_PID_T_FMT, thepid);
+
+ /* Unlink from check list */
+ previous_node->next_index = current_node->next_index;
+
+ /* Link to free list */
+ link_node_to_list(main_server, proctable_get_free_list(),
+ current_node, proc_table);
+ } else
+ previous_node = current_node;
+
+ current_node = next_node;
+ }
+
+ /*
+ Now link the check list back to the tail of idle list
+ */
+ if (check_list_header->next_index) {
+ safe_lock(main_server);
+ previous_node = proctable_get_idle_list();
+ current_node = &proc_table[previous_node->next_index];
+
+ /* Find the tail of idle list */
+ while (current_node != proc_table) {
+ previous_node = current_node;
+ current_node = &proc_table[current_node->next_index];
+ }
+
+ /* Link check list to the tail of idle list */
+ previous_node->next_index = check_list_header->next_index;
+ safe_unlock(main_server);
+ }
}
static apr_time_t lasterrorscan = 0;
static void scan_errorlist(server_rec * main_server)
{
- /*
- kill() and wait() every node in error list
- put them back to free list after that
- */
- void *dummy;
- fcgid_procnode *previous_node, *current_node, *next_node;
- apr_time_t now = apr_time_now();
- fcgid_procnode *error_list_header = proctable_get_error_list();
- fcgid_procnode *free_list_header = proctable_get_free_list();
- fcgid_procnode *proc_table = proctable_get_table_array();
- fcgid_procnode temp_error_header;
-
- /* Should I check the busy list? */
- if (procmgr_must_exit()
- || apr_time_sec(now) - apr_time_sec(lasterrorscan) <=
- g_error_scan_interval)
- return;
- lasterrorscan = now = apr_time_now();
-
- /* Try wait dead processes, restore to free list */
- /* Note: I can't keep the lock during the scan */
- safe_lock(main_server);
- temp_error_header.next_index = error_list_header->next_index;
- error_list_header->next_index = 0;
- safe_unlock(main_server);
-
- previous_node = &temp_error_header;
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
-
- if (proc_wait_process(main_server, current_node) !=
- APR_CHILD_NOTDONE) {
- /* Unlink from error list */
- previous_node->next_index = current_node->next_index;
-
- /* Link to free list */
- current_node->next_index = free_list_header->next_index;
- free_list_header->next_index = current_node - proc_table;
- } else
- previous_node = current_node;
-
- current_node = next_node;
- }
-
- /* Kill the left processes, wait() them in the next round */
- for (current_node = &proc_table[temp_error_header.next_index];
- current_node != proc_table;
- current_node = &proc_table[current_node->next_index]) {
- /* Try gracefully first */
- dummy = NULL;
- apr_pool_userdata_get(&dummy, HAS_GRACEFUL_KILL,
- current_node->proc_pool);
- if (!dummy) {
- proc_kill_gracefully(current_node, main_server);
- apr_pool_userdata_set("set", HAS_GRACEFUL_KILL,
- apr_pool_cleanup_null,
- current_node->proc_pool);
- } else {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: process %" APR_PID_T_FMT
- " graceful kill fail, sending SIGKILL",
- current_node->proc_id->pid);
- proc_kill_force(current_node, main_server);
- }
- }
-
- /* Link the temp error list back */
- safe_lock(main_server);
- /* Find the tail of error list */
- previous_node = error_list_header;
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- previous_node = current_node;
- current_node = &proc_table[current_node->next_index];
- }
- previous_node->next_index = temp_error_header.next_index;
- safe_unlock(main_server);
+ /*
+ kill() and wait() every node in error list
+ put them back to free list after that
+ */
+ void *dummy;
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ apr_time_t now = apr_time_now();
+ fcgid_procnode *error_list_header = proctable_get_error_list();
+ fcgid_procnode *free_list_header = proctable_get_free_list();
+ fcgid_procnode *proc_table = proctable_get_table_array();
+ fcgid_procnode temp_error_header;
+
+ /* Should I check the busy list? */
+ if (procmgr_must_exit()
+ || apr_time_sec(now) - apr_time_sec(lasterrorscan) <=
+ g_error_scan_interval)
+ return;
+ lasterrorscan = now = apr_time_now();
+
+ /* Try wait dead processes, restore to free list */
+ /* Note: I can't keep the lock during the scan */
+ safe_lock(main_server);
+ temp_error_header.next_index = error_list_header->next_index;
+ error_list_header->next_index = 0;
+ safe_unlock(main_server);
+
+ previous_node = &temp_error_header;
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+
+ if (proc_wait_process(main_server, current_node) !=
+ APR_CHILD_NOTDONE) {
+ /* Unlink from error list */
+ previous_node->next_index = current_node->next_index;
+
+ /* Link to free list */
+ current_node->next_index = free_list_header->next_index;
+ free_list_header->next_index = current_node - proc_table;
+ } else
+ previous_node = current_node;
+
+ current_node = next_node;
+ }
+
+ /* Kill the left processes, wait() them in the next round */
+ for (current_node = &proc_table[temp_error_header.next_index];
+ current_node != proc_table;
+ current_node = &proc_table[current_node->next_index]) {
+ /* Try gracefully first */
+ dummy = NULL;
+ apr_pool_userdata_get(&dummy, HAS_GRACEFUL_KILL,
+ current_node->proc_pool);
+ if (!dummy) {
+ proc_kill_gracefully(current_node, main_server);
+ apr_pool_userdata_set("set", HAS_GRACEFUL_KILL,
+ apr_pool_cleanup_null,
+ current_node->proc_pool);
+ } else {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: process %" APR_PID_T_FMT
+ " graceful kill fail, sending SIGKILL",
+ current_node->proc_id->pid);
+ proc_kill_force(current_node, main_server);
+ }
+ }
+
+ /* Link the temp error list back */
+ safe_lock(main_server);
+ /* Find the tail of error list */
+ previous_node = error_list_header;
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ previous_node = current_node;
+ current_node = &proc_table[current_node->next_index];
+ }
+ previous_node->next_index = temp_error_header.next_index;
+ safe_unlock(main_server);
}
static void kill_all_subprocess(server_rec * main_server)
{
- size_t i;
- int exitcode;
- apr_exit_why_e exitwhy;
- fcgid_procnode *proc_table = proctable_get_table_array();
-
- /* Kill gracefully */
- for (i = 0; i < proctable_get_table_size(); i++) {
- if (proc_table[i].proc_pool)
- proc_kill_gracefully(&proc_table[i], main_server);
- }
- apr_sleep(apr_time_from_sec(1));
-
- /* Kill with SIGKILL if it doesn't work */
- for (i = 0; i < proctable_get_table_size(); i++) {
- if (proc_table[i].proc_pool) {
- if (apr_proc_wait(proc_table[i].proc_id, &exitcode, &exitwhy,
- APR_NOWAIT) != APR_CHILD_NOTDONE) {
- proc_table[i].diewhy = FCGID_DIE_SHUTDOWN;
- proc_print_exit_info(&proc_table[i], exitcode, exitwhy,
- main_server);
- apr_pool_destroy(proc_table[i].proc_pool);
- proc_table[i].proc_pool = NULL;
- } else
- proc_kill_force(&proc_table[i], main_server);
- }
- }
-
- /* Wait again */
- for (i = 0; i < proctable_get_table_size(); i++) {
- if (proc_table[i].proc_pool) {
- if (apr_proc_wait(proc_table[i].proc_id, &exitcode, &exitwhy,
- APR_WAIT) != APR_CHILD_NOTDONE) {
- proc_table[i].diewhy = FCGID_DIE_SHUTDOWN;
- proc_print_exit_info(&proc_table[i], exitcode, exitwhy,
- main_server);
- apr_pool_destroy(proc_table[i].proc_pool);
- proc_table[i].proc_pool = NULL;
- }
- }
- }
+ size_t i;
+ int exitcode;
+ apr_exit_why_e exitwhy;
+ fcgid_procnode *proc_table = proctable_get_table_array();
+
+ /* Kill gracefully */
+ for (i = 0; i < proctable_get_table_size(); i++) {
+ if (proc_table[i].proc_pool)
+ proc_kill_gracefully(&proc_table[i], main_server);
+ }
+ apr_sleep(apr_time_from_sec(1));
+
+ /* Kill with SIGKILL if it doesn't work */
+ for (i = 0; i < proctable_get_table_size(); i++) {
+ if (proc_table[i].proc_pool) {
+ if (apr_proc_wait(proc_table[i].proc_id, &exitcode, &exitwhy,
+ APR_NOWAIT) != APR_CHILD_NOTDONE) {
+ proc_table[i].diewhy = FCGID_DIE_SHUTDOWN;
+ proc_print_exit_info(&proc_table[i], exitcode, exitwhy,
+ main_server);
+ apr_pool_destroy(proc_table[i].proc_pool);
+ proc_table[i].proc_pool = NULL;
+ } else
+ proc_kill_force(&proc_table[i], main_server);
+ }
+ }
+
+ /* Wait again */
+ for (i = 0; i < proctable_get_table_size(); i++) {
+ if (proc_table[i].proc_pool) {
+ if (apr_proc_wait(proc_table[i].proc_id, &exitcode, &exitwhy,
+ APR_WAIT) != APR_CHILD_NOTDONE) {
+ proc_table[i].diewhy = FCGID_DIE_SHUTDOWN;
+ proc_print_exit_info(&proc_table[i], exitcode, exitwhy,
+ main_server);
+ apr_pool_destroy(proc_table[i].proc_pool);
+ proc_table[i].proc_pool = NULL;
+ }
+ }
+ }
}
static void
fastcgi_spawn(fcgid_command * command, server_rec * main_server,
- apr_pool_t * configpool)
+ apr_pool_t * configpool)
{
- fcgid_procnode *free_list_header, *proctable_array,
- *procnode, *idle_list_header;
- fcgid_proc_info procinfo;
- apr_status_t rv;
- int i;
-
- free_list_header = proctable_get_free_list();
- idle_list_header = proctable_get_idle_list();
- proctable_array = proctable_get_table_array();
-
- /* Apply a slot from free list */
- safe_lock(main_server);
- if (free_list_header->next_index == 0) {
- safe_unlock(main_server);
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: too much processes, please increase FCGID_MAX_APPLICATION");
- return;
- }
- procnode = &proctable_array[free_list_header->next_index];
- free_list_header->next_index = procnode->next_index;
- procnode->next_index = 0;
- safe_unlock(main_server);
-
- /* Prepare to spawn */
- procnode->deviceid = command->deviceid;
- procnode->inode = command->inode;
- procnode->share_grp_id = command->share_grp_id;
- procnode->virtualhost = command->virtualhost;
- procnode->uid = command->uid;
- procnode->gid = command->gid;
- procnode->start_time = procnode->last_active_time = apr_time_now();
- procnode->requests_handled = 0;
- procnode->diewhy = FCGID_DIE_KILLSELF;
- procnode->proc_pool = NULL;
-
- procinfo.cgipath = command->cgipath;
- procinfo.configpool = configpool;
- procinfo.main_server = main_server;
- procinfo.uid = command->uid;
- procinfo.gid = command->gid;
- procinfo.userdir = command->userdir;
- if (apr_pool_create(&procnode->proc_pool, configpool) != APR_SUCCESS
- || (procinfo.proc_environ =
- apr_table_make(procnode->proc_pool, INITENV_CNT)) == NULL) {
- /* Link the node back to free list in this case */
- if (procnode->proc_pool)
- apr_pool_destroy(procnode->proc_pool);
- link_node_to_list(main_server, free_list_header, procnode,
- proctable_array);
-
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: can't create pool for process");
- return;
- }
- for (i = 0; i < INITENV_CNT; i++) {
- if (command->initenv_key[i][0] == '\0')
- break;
- apr_table_set(procinfo.proc_environ, command->initenv_key[i],
- command->initenv_val[i]);
- }
-
- /* Spawn the process now */
- if ((rv =
- proc_spawn_process(command->wrapperpath, &procinfo,
- procnode)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
- "mod_fcgid: spawn process %s error",
- command->cgipath);
-
- apr_pool_destroy(procnode->proc_pool);
- link_node_to_list(main_server, free_list_header,
- procnode, proctable_array);
- return;
- } else {
- /* The job done */
- link_node_to_list(main_server, idle_list_header,
- procnode, proctable_array);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
- "mod_fcgid: server %s:%s(%" APR_PID_T_FMT ") started",
- command->virtualhost, command->cgipath, procnode->proc_id->pid);
- register_spawn(main_server, procnode);
- }
+ fcgid_procnode *free_list_header, *proctable_array,
+ *procnode, *idle_list_header;
+ fcgid_proc_info procinfo;
+ apr_status_t rv;
+ int i;
+
+ free_list_header = proctable_get_free_list();
+ idle_list_header = proctable_get_idle_list();
+ proctable_array = proctable_get_table_array();
+
+ /* Apply a slot from free list */
+ safe_lock(main_server);
+ if (free_list_header->next_index == 0) {
+ safe_unlock(main_server);
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: too much processes, please increase FCGID_MAX_APPLICATION");
+ return;
+ }
+ procnode = &proctable_array[free_list_header->next_index];
+ free_list_header->next_index = procnode->next_index;
+ procnode->next_index = 0;
+ safe_unlock(main_server);
+
+ /* Prepare to spawn */
+ procnode->deviceid = command->deviceid;
+ procnode->inode = command->inode;
+ procnode->share_grp_id = command->share_grp_id;
+ procnode->virtualhost = command->virtualhost;
+ procnode->uid = command->uid;
+ procnode->gid = command->gid;
+ procnode->start_time = procnode->last_active_time = apr_time_now();
+ procnode->requests_handled = 0;
+ procnode->diewhy = FCGID_DIE_KILLSELF;
+ procnode->proc_pool = NULL;
+
+ procinfo.cgipath = command->cgipath;
+ procinfo.configpool = configpool;
+ procinfo.main_server = main_server;
+ procinfo.uid = command->uid;
+ procinfo.gid = command->gid;
+ procinfo.userdir = command->userdir;
+ if (apr_pool_create(&procnode->proc_pool, configpool) != APR_SUCCESS
+ || (procinfo.proc_environ =
+ apr_table_make(procnode->proc_pool, INITENV_CNT)) == NULL) {
+ /* Link the node back to free list in this case */
+ if (procnode->proc_pool)
+ apr_pool_destroy(procnode->proc_pool);
+ link_node_to_list(main_server, free_list_header, procnode,
+ proctable_array);
+
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: can't create pool for process");
+ return;
+ }
+ for (i = 0; i < INITENV_CNT; i++) {
+ if (command->initenv_key[i][0] == '\0')
+ break;
+ apr_table_set(procinfo.proc_environ, command->initenv_key[i],
+ command->initenv_val[i]);
+ }
+
+ /* Spawn the process now */
+ if ((rv =
+ proc_spawn_process(command->wrapperpath, &procinfo,
+ procnode)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
+ "mod_fcgid: spawn process %s error",
+ command->cgipath);
+
+ apr_pool_destroy(procnode->proc_pool);
+ link_node_to_list(main_server, free_list_header,
+ procnode, proctable_array);
+ return;
+ } else {
+ /* The job done */
+ link_node_to_list(main_server, idle_list_header,
+ procnode, proctable_array);
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
+ "mod_fcgid: server %s:%s(%" APR_PID_T_FMT ") started",
+ command->virtualhost, command->cgipath, procnode->proc_id->pid);
+ register_spawn(main_server, procnode);
+ }
}
apr_status_t pm_main(server_rec * main_server, apr_pool_t * configpool)
{
- fcgid_command command;
+ fcgid_command command;
- /* Initialize the variables from configuration */
- g_idle_timeout = get_idle_timeout(main_server);
- g_idle_scan_interval = get_idle_scan_interval(main_server);
- g_busy_scan_interval = get_busy_scan_interval(main_server);
- g_proc_lifetime = get_proc_lifetime(main_server);
- g_error_scan_interval = get_error_scan_interval(main_server);
- g_zombie_scan_interval = get_zombie_scan_interval(main_server);
- g_busy_timeout = get_busy_timeout(main_server);
- g_busy_timeout += 10;
-
- while (1) {
- if (procmgr_must_exit())
- break;
-
- /* Wait for command */
- if (procmgr_peek_cmd(&command, main_server) == APR_SUCCESS) {
- if (is_spawn_allowed(main_server, &command))
- fastcgi_spawn(&command, main_server, configpool);
-
- procmgr_finish_notify(main_server);
- }
-
- /* Move matched node to error list */
- scan_idlelist_zombie(main_server);
- scan_idlelist(main_server);
- scan_busylist(main_server);
-
- /* Kill() and wait() nodes in error list */
- scan_errorlist(main_server);
- }
+ /* Initialize the variables from configuration */
+ g_idle_timeout = get_idle_timeout(main_server);
+ g_idle_scan_interval = get_idle_scan_interval(main_server);
+ g_busy_scan_interval = get_busy_scan_interval(main_server);
+ g_proc_lifetime = get_proc_lifetime(main_server);
+ g_error_scan_interval = get_error_scan_interval(main_server);
+ g_zombie_scan_interval = get_zombie_scan_interval(main_server);
+ g_busy_timeout = get_busy_timeout(main_server);
+ g_busy_timeout += 10;
+
+ while (1) {
+ if (procmgr_must_exit())
+ break;
+
+ /* Wait for command */
+ if (procmgr_peek_cmd(&command, main_server) == APR_SUCCESS) {
+ if (is_spawn_allowed(main_server, &command))
+ fastcgi_spawn(&command, main_server, configpool);
+
+ procmgr_finish_notify(main_server);
+ }
+
+ /* Move matched node to error list */
+ scan_idlelist_zombie(main_server);
+ scan_idlelist(main_server);
+ scan_busylist(main_server);
+
+ /* Kill() and wait() nodes in error list */
+ scan_errorlist(main_server);
+ }
- /* Stop all processes */
- kill_all_subprocess(main_server);
+ /* Stop all processes */
+ kill_all_subprocess(main_server);
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proc.h
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proc.h?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proc.h (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proc.h Wed Mar 18 16:37:31 2009
@@ -23,49 +23,49 @@
#include "fcgid_proctbl.h"
typedef struct {
- apr_table_t *proc_environ;
- server_rec *main_server;
- apr_pool_t *configpool;
- char *cgipath;
- uid_t uid; /* For suEXEC */
- gid_t gid; /* For suEXEC */
- int userdir; /* For suEXEC */
+ apr_table_t *proc_environ;
+ server_rec *main_server;
+ apr_pool_t *configpool;
+ char *cgipath;
+ uid_t uid; /* For suEXEC */
+ gid_t gid; /* For suEXEC */
+ int userdir; /* For suEXEC */
} fcgid_proc_info;
typedef struct {
- int connect_timeout; /* in second */
- int communation_timeout; /* in second */
- void *ipc_handle_info;
- request_rec *request;
+ int connect_timeout; /* in second */
+ int communation_timeout; /* in second */
+ void *ipc_handle_info;
+ request_rec *request;
} fcgid_ipc;
apr_status_t proc_spawn_process(char *lpszwapper,
- fcgid_proc_info * procinfo,
- fcgid_procnode * procnode);
+ fcgid_proc_info * procinfo,
+ fcgid_procnode * procnode);
apr_status_t proc_kill_gracefully(fcgid_procnode * procnode,
- server_rec * main_server);
+ server_rec * main_server);
apr_status_t proc_kill_force(fcgid_procnode * procnode,
- server_rec * main_server);
+ server_rec * main_server);
apr_status_t proc_wait_process(server_rec * main_server,
- fcgid_procnode * procnode);
+ fcgid_procnode * procnode);
apr_status_t proc_connect_ipc(server_rec * main_server,
- fcgid_procnode * procnode,
- fcgid_ipc * ipc_handle);
+ fcgid_procnode * procnode,
+ fcgid_ipc * ipc_handle);
apr_status_t proc_read_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle, const char *buffer,
- apr_size_t * size);
+ fcgid_ipc * ipc_handle, const char *buffer,
+ apr_size_t * size);
apr_status_t proc_write_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle,
- apr_bucket_brigade * output_brigade);
+ fcgid_ipc * ipc_handle,
+ apr_bucket_brigade * output_brigade);
apr_status_t proc_close_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle);
+ fcgid_ipc * ipc_handle);
void proc_print_exit_info(fcgid_procnode * procnode, int exitcode,
- apr_exit_why_e exitwhy,
- server_rec * main_server);
+ apr_exit_why_e exitwhy,
+ server_rec * main_server);
#endif
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proctbl.h
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proctbl.h?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proctbl.h (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_proctbl.h Wed Mar 18 16:37:31 2009
@@ -29,31 +29,31 @@
#define FCGID_PROC_TABLE_SIZE (FCGID_MAX_APPLICATION+4)
/*
- nNextIndex is for making a node list, there are four kind of list:
- 1) free list: no process associate to this node
- 2) busy list: a process is associated, and it's handling request
- 3) idle list: a process is associated, and it's waiting request
- 4) error list: a process is associated, and killing the process now
+ nNextIndex is for making a node list, there are four kind of list:
+ 1) free list: no process associate to this node
+ 2) busy list: a process is associated, and it's handling request
+ 3) idle list: a process is associated, and it's waiting request
+ 4) error list: a process is associated, and killing the process now
*/
typedef struct {
- int next_index; /* the next array index in the list */
- apr_pool_t *proc_pool; /* pool for process */
- apr_proc_t *proc_id; /* the process id */
- char socket_path[_POSIX_PATH_MAX]; /* cgi application socket path */
- apr_ino_t inode; /* cgi file inode */
- apr_dev_t deviceid; /* cgi file device id */
- gid_t gid; /* for suEXEC */
- uid_t uid; /* for suEXEC */
- apr_size_t share_grp_id; /* cgi wrapper share group id */
- char *virtualhost; /* the virtualhost this process belongs to */
- apr_time_t start_time; /* the time of this process create */
- apr_time_t last_active_time; /* the time this process last active */
- int requests_handled; /* number of requests process has handled */
- char diewhy; /* why it die */
+ int next_index; /* the next array index in the list */
+ apr_pool_t *proc_pool; /* pool for process */
+ apr_proc_t *proc_id; /* the process id */
+ char socket_path[_POSIX_PATH_MAX]; /* cgi application socket path */
+ apr_ino_t inode; /* cgi file inode */
+ apr_dev_t deviceid; /* cgi file device id */
+ gid_t gid; /* for suEXEC */
+ uid_t uid; /* for suEXEC */
+ apr_size_t share_grp_id; /* cgi wrapper share group id */
+ char *virtualhost; /* the virtualhost this process belongs to */
+ apr_time_t start_time; /* the time of this process create */
+ apr_time_t last_active_time; /* the time this process last active */
+ int requests_handled; /* number of requests process has handled */
+ char diewhy; /* why it die */
} fcgid_procnode;
/* Macros for diewhy */
-#define FCGID_DIE_KILLSELF 0
+#define FCGID_DIE_KILLSELF 0
#define FCGID_DIE_IDLE_TIMEOUT 1
#define FCGID_DIE_LIFETIME_EXPIRED 2
#define FCGID_DIE_BUSY_TIMEOUT 3
@@ -62,18 +62,18 @@
#define FCGID_DIE_SHUTDOWN 6
typedef struct {
- int must_exit; /* All processes using this share memory must exit */
+ int must_exit; /* All processes using this share memory must exit */
} fcgid_global_share;
typedef struct {
- fcgid_global_share global;
- fcgid_procnode procnode_array[FCGID_PROC_TABLE_SIZE];
+ fcgid_global_share global;
+ fcgid_procnode procnode_array[FCGID_PROC_TABLE_SIZE];
} fcgid_share;
apr_status_t proctable_child_init(server_rec * main_server,
- apr_pool_t * pchild);
+ apr_pool_t * pchild);
apr_status_t proctable_post_config(server_rec * main_server,
- apr_pool_t * pconf);
+ apr_pool_t * pconf);
apr_status_t proctable_lock_table(void);
apr_status_t proctable_unlock_table(void);
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.c Wed Mar 18 16:37:31 2009
@@ -24,195 +24,195 @@
static size_t init_environment(char *buf, char **envp)
{
- char *spliter;
- int namelen, valuelen;
- char *cur_buf = buf;
- size_t buffer_size = 0;
-
- for (; *envp != NULL; envp++) {
- spliter = strchr(*envp, '=');
- if (spliter == NULL)
- continue;
-
- namelen = spliter - *envp;
- valuelen = strlen(spliter + 1);
-
- /* Put name length to buffer */
- if (namelen < 0x80) {
- if (!buf)
- buffer_size++;
- else
- *cur_buf++ = (unsigned char) namelen;
- } else {
- if (!buf)
- buffer_size += 4;
- else {
- *cur_buf++ = (unsigned char) ((namelen >> 24) | 0x80);
- *cur_buf++ = (unsigned char) (namelen >> 16);
- *cur_buf++ = (unsigned char) (namelen >> 8);
- *cur_buf++ = (unsigned char) namelen;
- }
- }
-
- /* Put value length to buffer */
- if (valuelen < 0x80) {
- if (!buf)
- buffer_size++;
- else
- *cur_buf++ = (unsigned char) valuelen;
- } else {
- if (!buf)
- buffer_size += 4;
- else {
- *cur_buf++ = (unsigned char) ((valuelen >> 24) | 0x80);
- *cur_buf++ = (unsigned char) (valuelen >> 16);
- *cur_buf++ = (unsigned char) (valuelen >> 8);
- *cur_buf++ = (unsigned char) valuelen;
- }
- }
-
- /* Now the name and body buffer */
- if (!buf) {
- buffer_size += namelen;
- buffer_size += valuelen;
- } else {
- memcpy(cur_buf, *envp, namelen);
- cur_buf += namelen;
- memcpy(cur_buf, spliter + 1, valuelen);
- cur_buf += valuelen;
- }
- }
- return buffer_size;
+ char *spliter;
+ int namelen, valuelen;
+ char *cur_buf = buf;
+ size_t buffer_size = 0;
+
+ for (; *envp != NULL; envp++) {
+ spliter = strchr(*envp, '=');
+ if (spliter == NULL)
+ continue;
+
+ namelen = spliter - *envp;
+ valuelen = strlen(spliter + 1);
+
+ /* Put name length to buffer */
+ if (namelen < 0x80) {
+ if (!buf)
+ buffer_size++;
+ else
+ *cur_buf++ = (unsigned char) namelen;
+ } else {
+ if (!buf)
+ buffer_size += 4;
+ else {
+ *cur_buf++ = (unsigned char) ((namelen >> 24) | 0x80);
+ *cur_buf++ = (unsigned char) (namelen >> 16);
+ *cur_buf++ = (unsigned char) (namelen >> 8);
+ *cur_buf++ = (unsigned char) namelen;
+ }
+ }
+
+ /* Put value length to buffer */
+ if (valuelen < 0x80) {
+ if (!buf)
+ buffer_size++;
+ else
+ *cur_buf++ = (unsigned char) valuelen;
+ } else {
+ if (!buf)
+ buffer_size += 4;
+ else {
+ *cur_buf++ = (unsigned char) ((valuelen >> 24) | 0x80);
+ *cur_buf++ = (unsigned char) (valuelen >> 16);
+ *cur_buf++ = (unsigned char) (valuelen >> 8);
+ *cur_buf++ = (unsigned char) valuelen;
+ }
+ }
+
+ /* Now the name and body buffer */
+ if (!buf) {
+ buffer_size += namelen;
+ buffer_size += valuelen;
+ } else {
+ memcpy(cur_buf, *envp, namelen);
+ cur_buf += namelen;
+ memcpy(cur_buf, spliter + 1, valuelen);
+ cur_buf += valuelen;
+ }
+ }
+ return buffer_size;
}
static void
init_begin_request_body(int role,
- FCGI_BeginRequestBody * begin_request_body)
+ FCGI_BeginRequestBody * begin_request_body)
{
- begin_request_body->roleB1 = (unsigned char) (((role >> 8) & 0xff));
- begin_request_body->roleB0 = (unsigned char) (role & 0xff);
- begin_request_body->flags = 0;
- memset(begin_request_body->reserved, 0,
- sizeof(begin_request_body->reserved));
+ begin_request_body->roleB1 = (unsigned char) (((role >> 8) & 0xff));
+ begin_request_body->roleB0 = (unsigned char) (role & 0xff);
+ begin_request_body->flags = 0;
+ memset(begin_request_body->reserved, 0,
+ sizeof(begin_request_body->reserved));
}
int
init_header(int type, int requestId, apr_size_t contentLength,
- apr_size_t paddingLength, FCGI_Header * header)
+ apr_size_t paddingLength, FCGI_Header * header)
{
- if (contentLength > 65535 || paddingLength > 255)
- return 0;
- header->version = FCGI_VERSION_1;
- header->type = (unsigned char) type;
- header->requestIdB1 = (unsigned char) ((requestId >> 8) & 0xff);
- header->requestIdB0 = (unsigned char) (requestId & 0xff);
- header->contentLengthB1 =
- (unsigned char) ((contentLength >> 8) & 0xff);
- header->contentLengthB0 = (unsigned char) ((contentLength) & 0xff);
- header->paddingLength = (unsigned char) paddingLength;
- header->reserved = 0;
- return 1;
+ if (contentLength > 65535 || paddingLength > 255)
+ return 0;
+ header->version = FCGI_VERSION_1;
+ header->type = (unsigned char) type;
+ header->requestIdB1 = (unsigned char) ((requestId >> 8) & 0xff);
+ header->requestIdB0 = (unsigned char) (requestId & 0xff);
+ header->contentLengthB1 =
+ (unsigned char) ((contentLength >> 8) & 0xff);
+ header->contentLengthB0 = (unsigned char) ((contentLength) & 0xff);
+ header->paddingLength = (unsigned char) paddingLength;
+ header->reserved = 0;
+ return 1;
}
int
build_begin_block(int role, server_rec * main_server,
- apr_bucket_alloc_t * alloc,
- apr_bucket_brigade * request_brigade)
+ apr_bucket_alloc_t * alloc,
+ apr_bucket_brigade * request_brigade)
{
- /* Alloc memory for begin request header & body */
- FCGI_Header *begin_request_header =
- apr_bucket_alloc(sizeof(FCGI_Header), alloc);
- FCGI_BeginRequestBody *begin_request_body =
- apr_bucket_alloc(sizeof(FCGI_BeginRequestBody), alloc);
- apr_bucket *bucket_header =
- apr_bucket_heap_create((const char *) begin_request_header,
- sizeof(*begin_request_header),
- apr_bucket_free,
- alloc);
- apr_bucket *bucket_body =
- apr_bucket_heap_create((const char *) begin_request_body,
- sizeof(*begin_request_body),
- apr_bucket_free,
- alloc);
-
- /* Sanity check */
- if (!begin_request_header || !begin_request_body
- || !bucket_header || !bucket_body) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memeory for begin request");
- return 0;
- }
-
- /* Initialize begin request header and body */
- if (!init_header(FCGI_BEGIN_REQUEST, 1, sizeof(FCGI_BeginRequestBody),
- 0, begin_request_header)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't init begin request header");
- return 0;
- }
- init_begin_request_body(role, begin_request_body);
-
- /* Append the header and body to request brigade */
- APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_header);
- APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_body);
+ /* Alloc memory for begin request header & body */
+ FCGI_Header *begin_request_header =
+ apr_bucket_alloc(sizeof(FCGI_Header), alloc);
+ FCGI_BeginRequestBody *begin_request_body =
+ apr_bucket_alloc(sizeof(FCGI_BeginRequestBody), alloc);
+ apr_bucket *bucket_header =
+ apr_bucket_heap_create((const char *) begin_request_header,
+ sizeof(*begin_request_header),
+ apr_bucket_free,
+ alloc);
+ apr_bucket *bucket_body =
+ apr_bucket_heap_create((const char *) begin_request_body,
+ sizeof(*begin_request_body),
+ apr_bucket_free,
+ alloc);
+
+ /* Sanity check */
+ if (!begin_request_header || !begin_request_body
+ || !bucket_header || !bucket_body) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memeory for begin request");
+ return 0;
+ }
+
+ /* Initialize begin request header and body */
+ if (!init_header(FCGI_BEGIN_REQUEST, 1, sizeof(FCGI_BeginRequestBody),
+ 0, begin_request_header)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't init begin request header");
+ return 0;
+ }
+ init_begin_request_body(role, begin_request_body);
+
+ /* Append the header and body to request brigade */
+ APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_header);
+ APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_body);
- return 1;
+ return 1;
}
int
build_env_block(server_rec * main_server, char **envp,
- apr_bucket_alloc_t * alloc,
- apr_bucket_brigade * request_brigade)
+ apr_bucket_alloc_t * alloc,
+ apr_bucket_brigade * request_brigade)
{
- /* Get the size of the destination buffer */
- apr_size_t bufsize = init_environment(NULL, envp);
+ /* Get the size of the destination buffer */
+ apr_size_t bufsize = init_environment(NULL, envp);
- /* Alloc memory for environment header and body */
- FCGI_Header *env_request_header =
- apr_bucket_alloc(sizeof(FCGI_Header), alloc);
- FCGI_Header *env_empty_header =
- apr_bucket_alloc(sizeof(FCGI_Header), alloc);
- char *buf = apr_bucket_alloc(bufsize, alloc);
- apr_bucket *bucket_header = apr_bucket_heap_create((const char *)
- env_request_header,
- sizeof
- (*env_request_header),
- apr_bucket_free,
- alloc);
- apr_bucket *bucket_body = apr_bucket_heap_create(buf, bufsize,
- apr_bucket_free,
- alloc);
- apr_bucket *bucket_empty_header = apr_bucket_heap_create((const char *)
- env_empty_header,
- sizeof
- (*env_empty_header),
- apr_bucket_free,
- alloc);
-
- if (!env_request_header || !buf || !env_empty_header || !bucket_header
- || !bucket_body || !bucket_empty_header) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for envion");
- return 0;
- }
-
- /* Initialize header and body */
- if (!init_header(FCGI_PARAMS, 1, bufsize, 0, env_request_header)
- || !init_header(FCGI_PARAMS, 1, 0, 0, env_empty_header)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't init env request header");
- return 0;
- }
- init_environment(buf, envp);
-
- /* Append the header and body to request brigade */
- APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_header);
- APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_body);
- APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_empty_header);
+ /* Alloc memory for environment header and body */
+ FCGI_Header *env_request_header =
+ apr_bucket_alloc(sizeof(FCGI_Header), alloc);
+ FCGI_Header *env_empty_header =
+ apr_bucket_alloc(sizeof(FCGI_Header), alloc);
+ char *buf = apr_bucket_alloc(bufsize, alloc);
+ apr_bucket *bucket_header = apr_bucket_heap_create((const char *)
+ env_request_header,
+ sizeof
+ (*env_request_header),
+ apr_bucket_free,
+ alloc);
+ apr_bucket *bucket_body = apr_bucket_heap_create(buf, bufsize,
+ apr_bucket_free,
+ alloc);
+ apr_bucket *bucket_empty_header = apr_bucket_heap_create((const char *)
+ env_empty_header,
+ sizeof
+ (*env_empty_header),
+ apr_bucket_free,
+ alloc);
+
+ if (!env_request_header || !buf || !env_empty_header || !bucket_header
+ || !bucket_body || !bucket_empty_header) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for envion");
+ return 0;
+ }
+
+ /* Initialize header and body */
+ if (!init_header(FCGI_PARAMS, 1, bufsize, 0, env_request_header)
+ || !init_header(FCGI_PARAMS, 1, 0, 0, env_empty_header)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't init env request header");
+ return 0;
+ }
+ init_environment(buf, envp);
+
+ /* Append the header and body to request brigade */
+ APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_header);
+ APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_body);
+ APR_BRIGADE_INSERT_TAIL(request_brigade, bucket_empty_header);
- return 1;
+ return 1;
}
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.h
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.h?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.h (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_protocol.h Wed Mar 18 16:37:31 2009
@@ -24,14 +24,14 @@
#define FCGI_LISTENSOCK_FILENO 0
typedef struct {
- unsigned char version;
- unsigned char type;
- unsigned char requestIdB1;
- unsigned char requestIdB0;
- unsigned char contentLengthB1;
- unsigned char contentLengthB0;
- unsigned char paddingLength;
- unsigned char reserved;
+ unsigned char version;
+ unsigned char type;
+ unsigned char requestIdB1;
+ unsigned char requestIdB0;
+ unsigned char contentLengthB1;
+ unsigned char contentLengthB0;
+ unsigned char paddingLength;
+ unsigned char reserved;
} FCGI_Header;
/*
@@ -67,10 +67,10 @@
#define FCGI_NULL_REQUEST_ID 0
typedef struct {
- unsigned char roleB1;
- unsigned char roleB0;
- unsigned char flags;
- unsigned char reserved[5];
+ unsigned char roleB1;
+ unsigned char roleB0;
+ unsigned char flags;
+ unsigned char reserved[5];
} FCGI_BeginRequestBody;
/*
@@ -101,13 +101,13 @@
#define FCGI_MPXS_CONNS "FCGI_MPXS_CONNS"
int init_header(int type, int requestId, apr_size_t contentLength,
- apr_size_t paddingLength, FCGI_Header * header);
+ apr_size_t paddingLength, FCGI_Header * header);
int build_begin_block(int role, server_rec * main_server,
- apr_bucket_alloc_t * alloc,
- apr_bucket_brigade * request_brigade);
+ apr_bucket_alloc_t * alloc,
+ apr_bucket_brigade * request_brigade);
int build_env_block(server_rec * main_server, char **envp,
- apr_bucket_alloc_t * alloc,
- apr_bucket_brigade * request_brigade);
+ apr_bucket_alloc_t * alloc,
+ apr_bucket_brigade * request_brigade);
#endif
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.c Wed Mar 18 16:37:31 2009
@@ -21,16 +21,16 @@
#define REGISTER_DEATH 2
struct fcgid_stat_node {
- apr_ino_t inode;
- dev_t deviceid;
- uid_t uid;
- gid_t gid;
- apr_size_t share_grp_id;
- char *virtualhost;
- int score;
- int process_counter;
- apr_time_t last_stat_time;
- struct fcgid_stat_node *next;
+ apr_ino_t inode;
+ dev_t deviceid;
+ uid_t uid;
+ gid_t gid;
+ apr_size_t share_grp_id;
+ char *virtualhost;
+ int score;
+ int process_counter;
+ apr_time_t last_stat_time;
+ struct fcgid_stat_node *next;
};
static apr_pool_t *g_stat_pool = NULL;
@@ -46,211 +46,211 @@
static void
register_life_death(server_rec * main_server,
- fcgid_procnode * procnode, int life_or_death)
+ fcgid_procnode * procnode, int life_or_death)
{
- struct fcgid_stat_node *previous_node, *current_node;
+ struct fcgid_stat_node *previous_node, *current_node;
- if (!g_stat_pool || !procnode)
- abort();
+ if (!g_stat_pool || !procnode)
+ abort();
- /* Can I find the node base on inode, device id and share group id? */
- previous_node = g_stat_list_header;
- for (current_node = previous_node;
- current_node != NULL; current_node = current_node->next) {
- if (current_node->inode == procnode->inode
- && current_node->deviceid == procnode->deviceid
- && current_node->share_grp_id == procnode->share_grp_id
- && current_node->virtualhost == procnode->virtualhost
- && current_node->uid == procnode->uid
- && current_node->gid == procnode->gid)
- break;
- previous_node = current_node;
- }
-
- if (current_node) {
- /* Found the node */
- apr_time_t now = apr_time_now();
-
- /* Increase the score first */
- if (life_or_death == REGISTER_LIFE) {
- current_node->score += g_spawn_score;
- current_node->process_counter++;
- } else {
- current_node->score += g_termination_score;
- current_node->process_counter--;
- }
-
- /* Decrease the score base on the time passing */
- current_node->score -= g_time_score * (int) (apr_time_sec(now)
- -
- apr_time_sec
- (current_node->
- last_stat_time));
-
- /* Make score reasonable */
- if (current_node->score < 0)
- current_node->score = 0;
-
- current_node->last_stat_time = now;
- } else {
- /* I can't find it, create one */
- current_node = apr_pcalloc(g_stat_pool, sizeof(*current_node));
- if (!current_node)
- return;
- current_node->deviceid = procnode->deviceid;
- current_node->inode = procnode->inode;
- current_node->share_grp_id = procnode->share_grp_id;
- current_node->virtualhost = procnode->virtualhost;
- current_node->uid = procnode->uid;
- current_node->gid = procnode->gid;
- current_node->last_stat_time = apr_time_now();
- current_node->score = 0;
- current_node->process_counter = 1;
- current_node->next = NULL;
-
- /* append it to stat list for next search */
- if (!previous_node)
- g_stat_list_header = current_node;
- else
- previous_node->next = current_node;
- }
+ /* Can I find the node base on inode, device id and share group id? */
+ previous_node = g_stat_list_header;
+ for (current_node = previous_node;
+ current_node != NULL; current_node = current_node->next) {
+ if (current_node->inode == procnode->inode
+ && current_node->deviceid == procnode->deviceid
+ && current_node->share_grp_id == procnode->share_grp_id
+ && current_node->virtualhost == procnode->virtualhost
+ && current_node->uid == procnode->uid
+ && current_node->gid == procnode->gid)
+ break;
+ previous_node = current_node;
+ }
+
+ if (current_node) {
+ /* Found the node */
+ apr_time_t now = apr_time_now();
+
+ /* Increase the score first */
+ if (life_or_death == REGISTER_LIFE) {
+ current_node->score += g_spawn_score;
+ current_node->process_counter++;
+ } else {
+ current_node->score += g_termination_score;
+ current_node->process_counter--;
+ }
+
+ /* Decrease the score base on the time passing */
+ current_node->score -= g_time_score * (int) (apr_time_sec(now)
+ -
+ apr_time_sec
+ (current_node->
+ last_stat_time));
+
+ /* Make score reasonable */
+ if (current_node->score < 0)
+ current_node->score = 0;
+
+ current_node->last_stat_time = now;
+ } else {
+ /* I can't find it, create one */
+ current_node = apr_pcalloc(g_stat_pool, sizeof(*current_node));
+ if (!current_node)
+ return;
+ current_node->deviceid = procnode->deviceid;
+ current_node->inode = procnode->inode;
+ current_node->share_grp_id = procnode->share_grp_id;
+ current_node->virtualhost = procnode->virtualhost;
+ current_node->uid = procnode->uid;
+ current_node->gid = procnode->gid;
+ current_node->last_stat_time = apr_time_now();
+ current_node->score = 0;
+ current_node->process_counter = 1;
+ current_node->next = NULL;
+
+ /* append it to stat list for next search */
+ if (!previous_node)
+ g_stat_list_header = current_node;
+ else
+ previous_node->next = current_node;
+ }
}
void spawn_control_init(server_rec * main_server, apr_pool_t * configpool)
{
- apr_status_t rv;
+ apr_status_t rv;
- if ((rv = apr_pool_create(&g_stat_pool, configpool)) != APR_SUCCESS) {
- /* Fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't create stat pool");
- exit(1);
- }
-
- /* Initialize the variables from configuration */
- g_time_score = get_time_score(main_server);
- g_termination_score = get_termination_score(main_server);
- g_spawn_score = get_spawn_score(main_server);
- g_score_uplimit = get_spawnscore_uplimit(main_server);
- g_max_process = get_max_process(main_server);
- g_max_class_process = get_max_class_process(main_server);
- g_min_class_process = get_min_class_process(main_server);
+ if ((rv = apr_pool_create(&g_stat_pool, configpool)) != APR_SUCCESS) {
+ /* Fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't create stat pool");
+ exit(1);
+ }
+
+ /* Initialize the variables from configuration */
+ g_time_score = get_time_score(main_server);
+ g_termination_score = get_termination_score(main_server);
+ g_spawn_score = get_spawn_score(main_server);
+ g_score_uplimit = get_spawnscore_uplimit(main_server);
+ g_max_process = get_max_process(main_server);
+ g_max_class_process = get_max_class_process(main_server);
+ g_min_class_process = get_min_class_process(main_server);
}
void
register_termination(server_rec * main_server, fcgid_procnode * procnode)
{
- register_life_death(main_server, procnode, REGISTER_DEATH);
- g_total_process--;
+ register_life_death(main_server, procnode, REGISTER_DEATH);
+ g_total_process--;
}
void register_spawn(server_rec * main_server, fcgid_procnode * procnode)
{
- register_life_death(main_server, procnode, REGISTER_LIFE);
- g_total_process++;
+ register_life_death(main_server, procnode, REGISTER_LIFE);
+ g_total_process++;
}
/*
- Spawn control is base on such strategy:
- 1. Increate score if application is terminated
- 2. Increate score if application is spawned
- 3. Decrease score each second while score is positive
- 4. Negative spawn request if score is higher than up limit
- 5. Negative spawn request if total process count higher than up limit
- 6. Negative spawn request if process count of this class higher than up limit
+ Spawn control is base on such strategy:
+ 1. Increate score if application is terminated
+ 2. Increate score if application is spawned
+ 3. Decrease score each second while score is positive
+ 4. Negative spawn request if score is higher than up limit
+ 5. Negative spawn request if total process count higher than up limit
+ 6. Negative spawn request if process count of this class higher than up limit
*/
int is_spawn_allowed(server_rec * main_server, fcgid_command * command)
{
- struct fcgid_stat_node *current_node;
+ struct fcgid_stat_node *current_node;
- if (!command || !g_stat_pool)
- return 1;
+ if (!command || !g_stat_pool)
+ return 1;
- /* Can I find the node base on inode, device id and share group id? */
- for (current_node = g_stat_list_header;
- current_node != NULL; current_node = current_node->next) {
- if (current_node->inode == command->inode
- && current_node->deviceid == command->deviceid
- && current_node->share_grp_id == command->share_grp_id
- && current_node->virtualhost == command->virtualhost
- && current_node->uid == command->uid
- && current_node->gid == command->gid)
- break;
- }
-
- if (!current_node)
- return 1;
- else {
- apr_time_t now = apr_time_now();
-
- current_node->score -= g_time_score * (int) (apr_time_sec(now)
- -
- apr_time_sec
- (current_node->
- last_stat_time));
- current_node->last_stat_time = now;
- if (current_node->score < 0)
- current_node->score = 0;
-
- /* Score is higher than up limit? */
- if (current_node->score >= g_score_uplimit) {
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
- "mod_fcgid: %s spawn score %d >= %d, skip the spawn request",
- command->cgipath, current_node->score,
- g_score_uplimit);
- return 0;
- }
-
- /* Total process count higher than up limit? */
- if (g_total_process >= g_max_process) {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
- "mod_fcgid: %s total process count %d >= %d, skip the spawn request",
- command->cgipath, g_total_process, g_max_process);
- return 0;
- }
-
- /*
- Process count of this class higher than up limit?
- */
- /* I need max class proccess count */
- if (current_node->process_counter >= g_max_class_process) {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
- "mod_fcgid: too much %s process(current:%d, max:%d), skip the spawn request",
- command->cgipath, current_node->process_counter,
- g_max_class_process);
- return 0;
- }
+ /* Can I find the node base on inode, device id and share group id? */
+ for (current_node = g_stat_list_header;
+ current_node != NULL; current_node = current_node->next) {
+ if (current_node->inode == command->inode
+ && current_node->deviceid == command->deviceid
+ && current_node->share_grp_id == command->share_grp_id
+ && current_node->virtualhost == command->virtualhost
+ && current_node->uid == command->uid
+ && current_node->gid == command->gid)
+ break;
+ }
+
+ if (!current_node)
+ return 1;
+ else {
+ apr_time_t now = apr_time_now();
+
+ current_node->score -= g_time_score * (int) (apr_time_sec(now)
+ -
+ apr_time_sec
+ (current_node->
+ last_stat_time));
+ current_node->last_stat_time = now;
+ if (current_node->score < 0)
+ current_node->score = 0;
+
+ /* Score is higher than up limit? */
+ if (current_node->score >= g_score_uplimit) {
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
+ "mod_fcgid: %s spawn score %d >= %d, skip the spawn request",
+ command->cgipath, current_node->score,
+ g_score_uplimit);
+ return 0;
+ }
+
+ /* Total process count higher than up limit? */
+ if (g_total_process >= g_max_process) {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
+ "mod_fcgid: %s total process count %d >= %d, skip the spawn request",
+ command->cgipath, g_total_process, g_max_process);
+ return 0;
+ }
+
+ /*
+ Process count of this class higher than up limit?
+ */
+ /* I need max class proccess count */
+ if (current_node->process_counter >= g_max_class_process) {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
+ "mod_fcgid: too much %s process(current:%d, max:%d), skip the spawn request",
+ command->cgipath, current_node->process_counter,
+ g_max_class_process);
+ return 0;
+ }
- return 1;
- }
+ return 1;
+ }
}
int is_kill_allowed(fcgid_procnode * procnode)
{
- struct fcgid_stat_node *previous_node, *current_node;
+ struct fcgid_stat_node *previous_node, *current_node;
- if (!g_stat_pool || !procnode)
- return 0;
+ if (!g_stat_pool || !procnode)
+ return 0;
- /* Can I find the node base on inode, device id and share group id? */
- previous_node = g_stat_list_header;
- for (current_node = previous_node;
- current_node != NULL; current_node = current_node->next) {
- if (current_node->inode == procnode->inode
- && current_node->deviceid == procnode->deviceid
- && current_node->share_grp_id == procnode->share_grp_id
- && current_node->virtualhost == procnode->virtualhost
- && current_node->uid == procnode->uid
- && current_node->gid == procnode->gid)
- break;
- previous_node = current_node;
- }
-
- if (current_node) {
- /* Found the node */
- if (current_node->process_counter <= g_min_class_process)
- return 0;
- }
+ /* Can I find the node base on inode, device id and share group id? */
+ previous_node = g_stat_list_header;
+ for (current_node = previous_node;
+ current_node != NULL; current_node = current_node->next) {
+ if (current_node->inode == procnode->inode
+ && current_node->deviceid == procnode->deviceid
+ && current_node->share_grp_id == procnode->share_grp_id
+ && current_node->virtualhost == procnode->virtualhost
+ && current_node->uid == procnode->uid
+ && current_node->gid == procnode->gid)
+ break;
+ previous_node = current_node;
+ }
+
+ if (current_node) {
+ /* Found the node */
+ if (current_node->process_counter <= g_min_class_process)
+ return 0;
+ }
- return 1;
+ return 1;
}
Modified: httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.h
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.h?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.h (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/fcgid_spawn_ctl.h Wed Mar 18 16:37:31 2009
@@ -22,7 +22,7 @@
void spawn_control_init(server_rec * main_server, apr_pool_t * configpool);
void register_termination(server_rec * main_server,
- fcgid_procnode * procnode);
+ fcgid_procnode * procnode);
void register_spawn(server_rec * main_server, fcgid_procnode * procnode);
int is_spawn_allowed(server_rec * main_server, fcgid_command * command);
int is_kill_allowed(fcgid_procnode * procnode);