convert tabs to spaces
git-svn-id: https://svn.apache.org/repos/asf/httpd/mod_fcgid/trunk@755634 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mod_fcgid/arch/unix/fcgid_pm_unix.c b/mod_fcgid/arch/unix/fcgid_pm_unix.c
index 2c0c4c4..bf385d5 100644
--- a/mod_fcgid/arch/unix/fcgid_pm_unix.c
+++ b/mod_fcgid/arch/unix/fcgid_pm_unix.c
@@ -12,7 +12,7 @@
#include "fcgid_spawn_ctl.h"
#include <unistd.h>
static apr_status_t create_process_manager(server_rec * main_server,
- apr_pool_t * configpool);
+ apr_pool_t * configpool);
static int g_wakeup_timeout = 3;
static apr_proc_t *g_process_manager = NULL;
@@ -27,474 +27,474 @@
static pid_t g_pm_pid;
static void signal_handler(int signo)
{
- /* Sanity check, Make sure I am not the subprocess. A subprocess may
- get signale after fork() and before execve() */
- if (getpid() != g_pm_pid) {
- exit(0);
- return;
- }
+ /* Sanity check, Make sure I am not the subprocess. A subprocess may
+ get signale after fork() and before execve() */
+ if (getpid() != g_pm_pid) {
+ exit(0);
+ return;
+ }
- if ((signo == SIGTERM) || (signo == SIGUSR1) || (signo == SIGHUP)) {
- g_caughtSigTerm = 1;
- /* Tell the world it's time to die */
- proctable_get_globalshare()->must_exit = 1;
- }
+ if ((signo == SIGTERM) || (signo == SIGUSR1) || (signo == SIGHUP)) {
+ g_caughtSigTerm = 1;
+ /* Tell the world it's time to die */
+ proctable_get_globalshare()->must_exit = 1;
+ }
}
static apr_status_t init_signal(server_rec * main_server)
{
- struct sigaction sa;
+ struct sigaction sa;
- /* Setup handlers */
- sa.sa_handler = signal_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = 0;
+ /* Setup handlers */
+ sa.sa_handler = signal_handler;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0;
- if (sigaction(SIGTERM, &sa, NULL) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: Can't install SIGTERM handler");
- return APR_EGENERAL;
- }
+ if (sigaction(SIGTERM, &sa, NULL) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: Can't install SIGTERM handler");
+ return APR_EGENERAL;
+ }
- /* Httpd restart */
- if (sigaction(SIGHUP, &sa, NULL) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: Can't install SIGHUP handler");
- return APR_EGENERAL;
- }
+ /* Httpd restart */
+ if (sigaction(SIGHUP, &sa, NULL) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: Can't install SIGHUP handler");
+ return APR_EGENERAL;
+ }
- /* Httpd graceful restart */
- if (sigaction(SIGUSR1, &sa, NULL) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: Can't install SIGUSR1 handler");
- return APR_EGENERAL;
- }
+ /* Httpd graceful restart */
+ if (sigaction(SIGUSR1, &sa, NULL) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: Can't install SIGUSR1 handler");
+ return APR_EGENERAL;
+ }
- /* Ignore SIGPIPE */
- sa.sa_handler = SIG_IGN;
- if (sigaction(SIGPIPE, &sa, NULL) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: Can't install SIGPIPE handler");
- return APR_EGENERAL;
- }
+ /* Ignore SIGPIPE */
+ sa.sa_handler = SIG_IGN;
+ if (sigaction(SIGPIPE, &sa, NULL) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: Can't install SIGPIPE handler");
+ return APR_EGENERAL;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
static void fcgid_maint(int reason, void *data, apr_wait_t status)
{
- apr_proc_t *proc = data;
- int mpm_state;
+ apr_proc_t *proc = data;
+ int mpm_state;
- switch (reason) {
- case APR_OC_REASON_DEATH:
- apr_proc_other_child_unregister(data);
- if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state) == APR_SUCCESS
- && mpm_state != AP_MPMQ_STOPPING) {
- ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
- "mod_fcgid: fcgid process manager died, restarting the server");
+ switch (reason) {
+ case APR_OC_REASON_DEATH:
+ apr_proc_other_child_unregister(data);
+ if (ap_mpm_query(AP_MPMQ_MPM_STATE, &mpm_state) == APR_SUCCESS
+ && mpm_state != AP_MPMQ_STOPPING) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
+ "mod_fcgid: fcgid process manager died, restarting the server");
- /* HACK: I can't just call create_process_manager() to
- restart a process manager, because it will use the dirty
- share memory, I have to kill myself a SIGHUP, to make
- a clean restart */
- if (kill(getpid(), SIGHUP) < 0) {
- ap_log_error(APLOG_MARK, APLOG_EMERG,
- apr_get_os_error(), NULL,
- "mod_fcgid: can' kill myself a signal SIGHUP");
- exit(0);
- }
- }
- break;
- case APR_OC_REASON_RESTART:
- apr_proc_other_child_unregister(data);
- break;
- case APR_OC_REASON_LOST:
- apr_proc_other_child_unregister(data);
- /* It hack here too, a note above */
- if (kill(getpid(), SIGHUP) < 0) {
- ap_log_error(APLOG_MARK, APLOG_EMERG,
- apr_get_os_error(), NULL,
- "mod_fcgid: can' kill myself a signal SIGHUP");
- exit(0);
- }
- break;
- case APR_OC_REASON_UNREGISTER:
- /* I don't think it's going to happen */
- kill(proc->pid, SIGHUP);
- break;
- }
+ /* HACK: I can't just call create_process_manager() to
+ restart a process manager, because it will use the dirty
+ share memory, I have to kill myself a SIGHUP, to make
+ a clean restart */
+ if (kill(getpid(), SIGHUP) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG,
+ apr_get_os_error(), NULL,
+ "mod_fcgid: can' kill myself a signal SIGHUP");
+ exit(0);
+ }
+ }
+ break;
+ case APR_OC_REASON_RESTART:
+ apr_proc_other_child_unregister(data);
+ break;
+ case APR_OC_REASON_LOST:
+ apr_proc_other_child_unregister(data);
+ /* It hack here too, a note above */
+ if (kill(getpid(), SIGHUP) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG,
+ apr_get_os_error(), NULL,
+ "mod_fcgid: can' kill myself a signal SIGHUP");
+ exit(0);
+ }
+ break;
+ case APR_OC_REASON_UNREGISTER:
+ /* I don't think it's going to happen */
+ kill(proc->pid, SIGHUP);
+ break;
+ }
}
static int set_group_privs(void)
{
- if (!geteuid()) {
- const char *name;
+ if (!geteuid()) {
+ const char *name;
- /* Get username if passed as a uid */
- if (unixd_config.user_name[0] == '#') {
- struct passwd *ent;
+ /* Get username if passed as a uid */
+ if (unixd_config.user_name[0] == '#') {
+ struct passwd *ent;
- uid_t uid = atoi(&unixd_config.user_name[1]);
+ uid_t uid = atoi(&unixd_config.user_name[1]);
- if ((ent = getpwuid(uid)) == NULL) {
- ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
- "getpwuid: couldn't determine user name from uid %u, "
- "you probably need to modify the User directive",
- (unsigned) uid);
- return -1;
- }
- name = ent->pw_name;
- }
+ if ((ent = getpwuid(uid)) == NULL) {
+ ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
+ "getpwuid: couldn't determine user name from uid %u, "
+ "you probably need to modify the User directive",
+ (unsigned) uid);
+ return -1;
+ }
+ name = ent->pw_name;
+ }
- else
- name = unixd_config.user_name;
+ else
+ name = unixd_config.user_name;
#if !defined(OS2) && !defined(TPF)
- /* OS/2 and TPF don't support groups. */
+ /* OS/2 and TPF don't support groups. */
- /*
- * Set the GID before initgroups(), since on some platforms
- * setgid() is known to zap the group list.
- */
- if (setgid(unixd_config.group_id) == -1) {
- ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
- "setgid: unable to set group id to Group %u",
- (unsigned) unixd_config.group_id);
- return -1;
- }
+ /*
+ * Set the GID before initgroups(), since on some platforms
+ * setgid() is known to zap the group list.
+ */
+ if (setgid(unixd_config.group_id) == -1) {
+ ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
+ "setgid: unable to set group id to Group %u",
+ (unsigned) unixd_config.group_id);
+ return -1;
+ }
- /* Reset `groups' attributes. */
- if (initgroups(name, unixd_config.group_id) == -1) {
- ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
- "initgroups: unable to set groups for User %s "
- "and Group %u", name,
- (unsigned) unixd_config.group_id);
- return -1;
- }
-#endif /* !defined(OS2) && !defined(TPF) */
- }
- return 0;
+ /* Reset `groups' attributes. */
+ if (initgroups(name, unixd_config.group_id) == -1) {
+ ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
+ "initgroups: unable to set groups for User %s "
+ "and Group %u", name,
+ (unsigned) unixd_config.group_id);
+ return -1;
+ }
+#endif /* !defined(OS2) && !defined(TPF) */
+ }
+ return 0;
}
/* Base on unixd_setup_child() */
static int suexec_setup_child(void)
{
- if (set_group_privs()) {
- exit(-1);
- }
+ if (set_group_privs()) {
+ exit(-1);
+ }
- /* Only try to switch if we're running as root */
- if (!geteuid() && (seteuid(unixd_config.user_id) == -1)) {
- ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
- "setuid: unable to change to uid: %ld",
- (long) unixd_config.user_id);
- exit(-1);
- }
- return 0;
+ /* Only try to switch if we're running as root */
+ if (!geteuid() && (seteuid(unixd_config.user_id) == -1)) {
+ ap_log_error(APLOG_MARK, APLOG_ALERT, errno, NULL,
+ "setuid: unable to change to uid: %ld",
+ (long) unixd_config.user_id);
+ exit(-1);
+ }
+ return 0;
}
static apr_status_t
create_process_manager(server_rec * main_server, apr_pool_t * configpool)
{
- apr_status_t rv;
+ apr_status_t rv;
- g_process_manager =
- (apr_proc_t *) apr_pcalloc(configpool, sizeof(*g_process_manager));
- rv = apr_proc_fork(g_process_manager, configpool);
- if (rv == APR_INCHILD) {
- /* I am the child */
- g_pm_pid = getpid();
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
- "mod_fcgid: Process manager %d started", getpid());
+ g_process_manager =
+ (apr_proc_t *) apr_pcalloc(configpool, sizeof(*g_process_manager));
+ rv = apr_proc_fork(g_process_manager, configpool);
+ if (rv == APR_INCHILD) {
+ /* I am the child */
+ g_pm_pid = getpid();
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
+ "mod_fcgid: Process manager %d started", getpid());
- if ((rv = init_signal(main_server)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, LOG_EMERG, rv, main_server,
- "mod_fcgid: can't intall signal handler, exit now");
- exit(1);
- }
+ if ((rv = init_signal(main_server)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, LOG_EMERG, rv, main_server,
+ "mod_fcgid: can't intall signal handler, exit now");
+ exit(1);
+ }
- /* if running as root, switch to configured user */
- if (unixd_config.suexec_enabled) {
- if (getuid() != 0) {
- ap_log_error(APLOG_MARK, LOG_EMERG, rv, main_server,
- "mod_fcgid: current user is not root while suexec is enabled, exit now");
- exit(1);
- }
- suexec_setup_child();
- } else
- unixd_setup_child();
- apr_file_pipe_timeout_set(g_pm_read_pipe,
- apr_time_from_sec(g_wakeup_timeout));
- apr_file_close(g_ap_write_pipe);
- apr_file_close(g_ap_read_pipe);
+ /* if running as root, switch to configured user */
+ if (unixd_config.suexec_enabled) {
+ if (getuid() != 0) {
+ ap_log_error(APLOG_MARK, LOG_EMERG, rv, main_server,
+ "mod_fcgid: current user is not root while suexec is enabled, exit now");
+ exit(1);
+ }
+ suexec_setup_child();
+ } else
+ unixd_setup_child();
+ apr_file_pipe_timeout_set(g_pm_read_pipe,
+ apr_time_from_sec(g_wakeup_timeout));
+ apr_file_close(g_ap_write_pipe);
+ apr_file_close(g_ap_read_pipe);
- /* Initialize spawn controler */
- spawn_control_init(main_server, configpool);
+ /* Initialize spawn controler */
+ spawn_control_init(main_server, configpool);
- pm_main(main_server, configpool);
+ pm_main(main_server, configpool);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
- "mod_fcgid: Process manager %d stopped", getpid());
- exit(0);
- } else if (rv != APR_INPARENT) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, errno, main_server,
- "mod_fcgid: Create process manager error");
- exit(1);
- }
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
+ "mod_fcgid: Process manager %d stopped", getpid());
+ exit(0);
+ } else if (rv != APR_INPARENT) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, errno, main_server,
+ "mod_fcgid: Create process manager error");
+ exit(1);
+ }
- /* I am the parent
- I will send the stop signal in procmgr_stop_procmgr() */
- apr_pool_note_subprocess(configpool, g_process_manager,
- APR_KILL_ONLY_ONCE);
- apr_proc_other_child_register(g_process_manager, fcgid_maint,
- g_process_manager, NULL, configpool);
+ /* I am the parent
+ I will send the stop signal in procmgr_stop_procmgr() */
+ apr_pool_note_subprocess(configpool, g_process_manager,
+ APR_KILL_ONLY_ONCE);
+ apr_proc_other_child_register(g_process_manager, fcgid_maint,
+ g_process_manager, NULL, configpool);
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
procmgr_child_init(server_rec * main_server, apr_pool_t * configpool)
{
- apr_status_t rv;
+ apr_status_t rv;
- if ((rv = apr_global_mutex_child_init(&g_pipelock,
- g_pipelock_name,
- main_server->process->pconf)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: apr_global_mutex_child_init error for pipe mutex");
- exit(1);
- }
+ if ((rv = apr_global_mutex_child_init(&g_pipelock,
+ g_pipelock_name,
+ main_server->process->pconf)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: apr_global_mutex_child_init error for pipe mutex");
+ exit(1);
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
procmgr_post_config(server_rec * main_server, apr_pool_t * configpool)
{
- apr_status_t rv;
- apr_finfo_t finfo;
- int error_scan_interval, busy_scan_interval, idle_scan_interval;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+ int error_scan_interval, busy_scan_interval, idle_scan_interval;
- /* Calculate procmgr_peek_cmd wake up interval */
- error_scan_interval = get_error_scan_interval(main_server);
- busy_scan_interval = get_busy_scan_interval(main_server);
- idle_scan_interval = get_idle_scan_interval(main_server);
- g_wakeup_timeout = fcgid_min(error_scan_interval, busy_scan_interval);
- g_wakeup_timeout = fcgid_min(idle_scan_interval, g_wakeup_timeout);
- if (g_wakeup_timeout == 0)
- g_wakeup_timeout = 1; /* Make it reasonable */
+ /* Calculate procmgr_peek_cmd wake up interval */
+ error_scan_interval = get_error_scan_interval(main_server);
+ busy_scan_interval = get_busy_scan_interval(main_server);
+ idle_scan_interval = get_idle_scan_interval(main_server);
+ g_wakeup_timeout = fcgid_min(error_scan_interval, busy_scan_interval);
+ g_wakeup_timeout = fcgid_min(idle_scan_interval, g_wakeup_timeout);
+ if (g_wakeup_timeout == 0)
+ g_wakeup_timeout = 1; /* Make it reasonable */
- rv = apr_stat(&finfo, get_socketpath(main_server), APR_FINFO_USER,
- configpool);
- if (rv != APR_SUCCESS || !(finfo.valid & APR_FINFO_USER)
- || finfo.user != unixd_config.user_id) {
- /* Make dir for unix domain socket */
- if ((rv = apr_dir_make_recursive(get_socketpath(main_server),
- APR_UREAD | APR_UWRITE |
- APR_UEXECUTE,
- configpool)) != APR_SUCCESS
- || chown(get_socketpath(main_server), unixd_config.user_id,
- -1) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
- "mod_fcgid: Can't create unix socket dir");
- exit(1);
- }
- }
+ rv = apr_stat(&finfo, get_socketpath(main_server), APR_FINFO_USER,
+ configpool);
+ if (rv != APR_SUCCESS || !(finfo.valid & APR_FINFO_USER)
+ || finfo.user != unixd_config.user_id) {
+ /* Make dir for unix domain socket */
+ if ((rv = apr_dir_make_recursive(get_socketpath(main_server),
+ APR_UREAD | APR_UWRITE |
+ APR_UEXECUTE,
+ configpool)) != APR_SUCCESS
+ || chown(get_socketpath(main_server), unixd_config.user_id,
+ -1) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
+ "mod_fcgid: Can't create unix socket dir");
+ exit(1);
+ }
+ }
- /* Create pipes to communicate between process manager and apache */
- if ((rv = apr_file_pipe_create(&g_pm_read_pipe, &g_ap_write_pipe,
- configpool)) != APR_SUCCESS
- || (rv = apr_file_pipe_create(&g_ap_read_pipe, &g_pm_write_pipe,
- configpool))) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
- "mod_fcgid: Can't create pipe between PM and stub");
- return rv;
- }
+ /* Create pipes to communicate between process manager and apache */
+ if ((rv = apr_file_pipe_create(&g_pm_read_pipe, &g_ap_write_pipe,
+ configpool)) != APR_SUCCESS
+ || (rv = apr_file_pipe_create(&g_ap_read_pipe, &g_pm_write_pipe,
+ configpool))) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
+ "mod_fcgid: Can't create pipe between PM and stub");
+ return rv;
+ }
- /* Create mutex for pipe reading and writing */
- if ((rv =
- apr_global_mutex_create(&g_pipelock, tmpnam(g_pipelock_name),
- APR_LOCK_DEFAULT,
- main_server->process->pconf)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't create global pipe mutex");
- exit(1);
- }
- if ((rv = unixd_set_global_mutex_perms(g_pipelock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't set global pipe mutex perms");
- exit(1);
- }
+ /* Create mutex for pipe reading and writing */
+ if ((rv =
+ apr_global_mutex_create(&g_pipelock, tmpnam(g_pipelock_name),
+ APR_LOCK_DEFAULT,
+ main_server->process->pconf)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't create global pipe mutex");
+ exit(1);
+ }
+ if ((rv = unixd_set_global_mutex_perms(g_pipelock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't set global pipe mutex perms");
+ exit(1);
+ }
- /* Create process manager process */
- return create_process_manager(main_server, configpool);
+ /* Create process manager process */
+ return create_process_manager(main_server, configpool);
}
void procmgr_init_spawn_cmd(fcgid_command * command, request_rec * r,
- const char *argv0, dev_t deviceid,
- apr_ino_t inode, apr_size_t share_grp_id)
+ const char *argv0, dev_t deviceid,
+ apr_ino_t inode, apr_size_t share_grp_id)
{
- server_rec *main_server = r->server;
- ap_unix_identity_t *ugid;
- apr_table_t *initenv;
- const apr_array_header_t *initenv_arr;
- const apr_table_entry_t *initenv_entry;
- fcgid_wrapper_conf *wrapperconf;
- int i;
+ server_rec *main_server = r->server;
+ ap_unix_identity_t *ugid;
+ apr_table_t *initenv;
+ const apr_array_header_t *initenv_arr;
+ const apr_table_entry_t *initenv_entry;
+ fcgid_wrapper_conf *wrapperconf;
+ int i;
- memset(command, 0, sizeof(*command));
+ memset(command, 0, sizeof(*command));
- /* suEXEC check */
- if ((ugid = ap_run_get_suexec_identity(r))) {
- command->uid = ugid->uid;
- command->gid = ugid->gid;
- command->userdir = ugid->userdir;
- } else {
- command->uid = (uid_t) - 1;
- command->gid = (gid_t) - 1;
- command->userdir = 0;
- }
+ /* suEXEC check */
+ if ((ugid = ap_run_get_suexec_identity(r))) {
+ command->uid = ugid->uid;
+ command->gid = ugid->gid;
+ command->userdir = ugid->userdir;
+ } else {
+ command->uid = (uid_t) - 1;
+ command->gid = (gid_t) - 1;
+ command->userdir = 0;
+ }
- /* Environment variables */
- initenv = get_default_env_vars(r);
- if (initenv) {
- initenv_arr = apr_table_elts(initenv);
- initenv_entry = (apr_table_entry_t *) initenv_arr->elts;
- if (initenv_arr->nelts > INITENV_CNT)
- ap_log_error(APLOG_MARK, LOG_WARNING, 0, main_server,
- "mod_fcgid: too much environment variables, Please increase INITENV_CNT in fcgid_pm.h and recompile module mod_fcgid");
+ /* Environment variables */
+ initenv = get_default_env_vars(r);
+ if (initenv) {
+ initenv_arr = apr_table_elts(initenv);
+ initenv_entry = (apr_table_entry_t *) initenv_arr->elts;
+ if (initenv_arr->nelts > INITENV_CNT)
+ ap_log_error(APLOG_MARK, LOG_WARNING, 0, main_server,
+ "mod_fcgid: too much environment variables, Please increase INITENV_CNT in fcgid_pm.h and recompile module mod_fcgid");
- for (i = 0; i < initenv_arr->nelts && i < INITENV_CNT; ++i) {
- if (initenv_entry[i].key == NULL
- || initenv_entry[i].key[0] == '\0')
- break;
- strncpy(command->initenv_key[i], initenv_entry[i].key,
- INITENV_KEY_LEN);
- command->initenv_key[i][INITENV_KEY_LEN - 1] = '\0';
- strncpy(command->initenv_val[i], initenv_entry[i].val,
- INITENV_VAL_LEN);
- command->initenv_val[i][INITENV_VAL_LEN - 1] = '\0';
- }
- }
+ for (i = 0; i < initenv_arr->nelts && i < INITENV_CNT; ++i) {
+ if (initenv_entry[i].key == NULL
+ || initenv_entry[i].key[0] == '\0')
+ break;
+ strncpy(command->initenv_key[i], initenv_entry[i].key,
+ INITENV_KEY_LEN);
+ command->initenv_key[i][INITENV_KEY_LEN - 1] = '\0';
+ strncpy(command->initenv_val[i], initenv_entry[i].val,
+ INITENV_VAL_LEN);
+ command->initenv_val[i][INITENV_VAL_LEN - 1] = '\0';
+ }
+ }
- strncpy(command->cgipath, argv0, _POSIX_PATH_MAX);
- command->cgipath[_POSIX_PATH_MAX - 1] = '\0';
- command->deviceid = deviceid;
- command->inode = inode;
- command->share_grp_id = share_grp_id;
- command->virtualhost = r->server->server_hostname;
+ strncpy(command->cgipath, argv0, _POSIX_PATH_MAX);
+ command->cgipath[_POSIX_PATH_MAX - 1] = '\0';
+ command->deviceid = deviceid;
+ command->inode = inode;
+ command->share_grp_id = share_grp_id;
+ command->virtualhost = r->server->server_hostname;
- /* Update fcgid_command with wrapper info */
- command->wrapperpath[0] = '\0';
- if ((wrapperconf = get_wrapper_info(argv0, r))) {
- strncpy(command->wrapperpath, wrapperconf->args, _POSIX_PATH_MAX);
- command->wrapperpath[_POSIX_PATH_MAX - 1] = '\0';
- command->deviceid = wrapperconf->deviceid;
- command->inode = wrapperconf->inode;
- command->share_grp_id = wrapperconf->share_group_id;
- }
+ /* Update fcgid_command with wrapper info */
+ command->wrapperpath[0] = '\0';
+ if ((wrapperconf = get_wrapper_info(argv0, r))) {
+ strncpy(command->wrapperpath, wrapperconf->args, _POSIX_PATH_MAX);
+ command->wrapperpath[_POSIX_PATH_MAX - 1] = '\0';
+ command->deviceid = wrapperconf->deviceid;
+ command->inode = wrapperconf->inode;
+ command->share_grp_id = wrapperconf->share_group_id;
+ }
}
apr_status_t procmgr_post_spawn_cmd(fcgid_command * command,
- request_rec * r)
+ request_rec * r)
{
- apr_status_t rv;
- char notifybyte;
- apr_size_t nbytes = sizeof(*command);
- server_rec *main_server = r->server;
+ apr_status_t rv;
+ char notifybyte;
+ apr_size_t nbytes = sizeof(*command);
+ server_rec *main_server = r->server;
- /* Sanity check first */
- if (g_caughtSigTerm || !g_ap_write_pipe)
- return APR_SUCCESS;
+ /* Sanity check first */
+ if (g_caughtSigTerm || !g_ap_write_pipe)
+ return APR_SUCCESS;
- /* Get the global mutex before posting the request */
- if ((rv = apr_global_mutex_lock(g_pipelock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: can't get pipe mutex");
- exit(0);
- }
+ /* Get the global mutex before posting the request */
+ if ((rv = apr_global_mutex_lock(g_pipelock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: can't get pipe mutex");
+ exit(0);
+ }
- if ((rv =
- apr_file_write_full(g_ap_write_pipe, command, nbytes,
- NULL)) != APR_SUCCESS) {
- /* Just print some error log and fall through */
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: can't write spawn command");
- } else {
- /* Wait the finish notify while send the request successfully */
- nbytes = sizeof(notifybyte);
- if ((rv =
- apr_file_read(g_ap_read_pipe, ¬ifybyte,
- &nbytes)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: can't get notify from process manager");
- }
- }
+ if ((rv =
+ apr_file_write_full(g_ap_write_pipe, command, nbytes,
+ NULL)) != APR_SUCCESS) {
+ /* Just print some error log and fall through */
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: can't write spawn command");
+ } else {
+ /* Wait the finish notify while send the request successfully */
+ nbytes = sizeof(notifybyte);
+ if ((rv =
+ apr_file_read(g_ap_read_pipe, ¬ifybyte,
+ &nbytes)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: can't get notify from process manager");
+ }
+ }
- /* Release the lock */
- if ((rv = apr_global_mutex_unlock(g_pipelock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: can't release pipe mutex");
- exit(0);
- }
+ /* Release the lock */
+ if ((rv = apr_global_mutex_unlock(g_pipelock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: can't release pipe mutex");
+ exit(0);
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t procmgr_finish_notify(server_rec * main_server)
{
- apr_status_t rv;
- char notifybyte = 'p';
- apr_size_t nbytes = sizeof(notifybyte);
+ apr_status_t rv;
+ char notifybyte = 'p';
+ apr_size_t nbytes = sizeof(notifybyte);
- if ((rv =
- apr_file_write(g_pm_write_pipe, ¬ifybyte,
- &nbytes)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: can't send notify from process manager");
- }
+ if ((rv =
+ apr_file_write(g_pm_write_pipe, ¬ifybyte,
+ &nbytes)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: can't send notify from process manager");
+ }
- return rv;
+ return rv;
}
#define FOR_READ 1
apr_status_t procmgr_peek_cmd(fcgid_command * command,
- server_rec * main_server)
+ server_rec * main_server)
{
- apr_status_t rv;
+ apr_status_t rv;
- /* Sanity check */
- if (!g_pm_read_pipe)
- return APR_EPIPE;
+ /* Sanity check */
+ if (!g_pm_read_pipe)
+ return APR_EPIPE;
- /* Wait for next command */
- rv = apr_wait_for_io_or_timeout(g_pm_read_pipe, NULL, FOR_READ);
+ /* Wait for next command */
+ rv = apr_wait_for_io_or_timeout(g_pm_read_pipe, NULL, FOR_READ);
- /* Log any unexpect result */
- if (rv != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(rv)) {
- ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
- "mod_fcgid: wait io error while getting message from pipe");
- return rv;
- }
+ /* Log any unexpect result */
+ if (rv != APR_SUCCESS && !APR_STATUS_IS_TIMEUP(rv)) {
+ ap_log_error(APLOG_MARK, LOG_WARNING, rv, main_server,
+ "mod_fcgid: wait io error while getting message from pipe");
+ return rv;
+ }
- /* Timeout */
- if (rv != APR_SUCCESS)
- return rv;
+ /* Timeout */
+ if (rv != APR_SUCCESS)
+ return rv;
- return apr_file_read_full(g_pm_read_pipe, command, sizeof(*command),
- NULL);
+ return apr_file_read_full(g_pm_read_pipe, command, sizeof(*command),
+ NULL);
}
int procmgr_must_exit()
{
- return g_caughtSigTerm;
+ return g_caughtSigTerm;
}
apr_status_t procmgr_stop_procmgr(void *server)
{
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
diff --git a/mod_fcgid/arch/unix/fcgid_proc_unix.c b/mod_fcgid/arch/unix/fcgid_proc_unix.c
index ace982d..c9f3c39 100644
--- a/mod_fcgid/arch/unix/fcgid_proc_unix.c
+++ b/mod_fcgid/arch/unix/fcgid_proc_unix.c
@@ -1,7 +1,7 @@
#include <unistd.h>
#include <sys/un.h>
#include <sys/types.h>
-#include <netinet/tcp.h> /* For TCP_NODELAY */
+#include <netinet/tcp.h> /* For TCP_NODELAY */
#include <sys/poll.h>
#define CORE_PRIVATE
#include "httpd.h"
@@ -24,7 +24,7 @@
#include "fcgid_spawn_ctl.h"
#define DEFAULT_FCGID_LISTENBACKLOG 5
typedef struct {
- int handle_socket;
+ int handle_socket;
} fcgid_namedpipe_handle;
static int g_process_counter = 0;
@@ -32,804 +32,804 @@
static const char *g_socket_dir = NULL;
static apr_status_t ap_unix_create_privileged_process(apr_proc_t * newproc,
- const char *progname,
- const char *const
- *args, const char *const
- *env,
- apr_procattr_t *
- attr,
- ap_unix_identity_t *
- ugid, apr_pool_t * p)
+ const char *progname,
+ const char *const
+ *args, const char *const
+ *env,
+ apr_procattr_t *
+ attr,
+ ap_unix_identity_t *
+ ugid, apr_pool_t * p)
{
- int i = 0;
- const char **newargs;
- char *newprogname;
- char *execuser, *execgroup;
- const char *argv0;
+ int i = 0;
+ const char **newargs;
+ char *newprogname;
+ char *execuser, *execgroup;
+ const char *argv0;
- if (!unixd_config.suexec_enabled) {
- return apr_proc_create(newproc, progname, args, env, attr, p);
- }
+ if (!unixd_config.suexec_enabled) {
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+ }
- argv0 = ap_strrchr_c(progname, '/');
- /* Allow suexec's "/" check to succeed */
- if (argv0 != NULL) {
- argv0++;
- } else {
- argv0 = progname;
- }
+ argv0 = ap_strrchr_c(progname, '/');
+ /* Allow suexec's "/" check to succeed */
+ if (argv0 != NULL) {
+ argv0++;
+ } else {
+ argv0 = progname;
+ }
- if (ugid->userdir) {
- execuser = apr_psprintf(p, "~%ld", (long) ugid->uid);
- } else {
- execuser = apr_psprintf(p, "%ld", (long) ugid->uid);
- }
- execgroup = apr_psprintf(p, "%ld", (long) ugid->gid);
+ if (ugid->userdir) {
+ execuser = apr_psprintf(p, "~%ld", (long) ugid->uid);
+ } else {
+ execuser = apr_psprintf(p, "%ld", (long) ugid->uid);
+ }
+ execgroup = apr_psprintf(p, "%ld", (long) ugid->gid);
- if (!execuser || !execgroup) {
- return APR_ENOMEM;
- }
+ if (!execuser || !execgroup) {
+ return APR_ENOMEM;
+ }
- i = 0;
- if (args) {
- while (args[i]) {
- i++;
- }
- }
- /* allocate space for 4 new args, the input args, and a null terminator */
- newargs = apr_palloc(p, sizeof(char *) * (i + 4));
- newprogname = SUEXEC_BIN;
- newargs[0] = SUEXEC_BIN;
- newargs[1] = execuser;
- newargs[2] = execgroup;
- newargs[3] = apr_pstrdup(p, argv0);
+ i = 0;
+ if (args) {
+ while (args[i]) {
+ i++;
+ }
+ }
+ /* allocate space for 4 new args, the input args, and a null terminator */
+ newargs = apr_palloc(p, sizeof(char *) * (i + 4));
+ newprogname = SUEXEC_BIN;
+ newargs[0] = SUEXEC_BIN;
+ newargs[1] = execuser;
+ newargs[2] = execgroup;
+ newargs[3] = apr_pstrdup(p, argv0);
- /*
- ** using a shell to execute suexec makes no sense thus
- ** we force everything to be APR_PROGRAM, and never
- ** APR_SHELLCMD
- */
- if (apr_procattr_cmdtype_set(attr, APR_PROGRAM) != APR_SUCCESS) {
- return APR_EGENERAL;
- }
+ /*
+ ** using a shell to execute suexec makes no sense thus
+ ** we force everything to be APR_PROGRAM, and never
+ ** APR_SHELLCMD
+ */
+ if (apr_procattr_cmdtype_set(attr, APR_PROGRAM) != APR_SUCCESS) {
+ return APR_EGENERAL;
+ }
- i = 1;
- do {
- newargs[i + 3] = args[i];
- } while (args[i++]);
+ i = 1;
+ do {
+ newargs[i + 3] = args[i];
+ } while (args[i++]);
- return apr_proc_create(newproc, newprogname, newargs, env, attr, p);
+ return apr_proc_create(newproc, newprogname, newargs, env, attr, p);
}
static apr_status_t fcgid_create_privileged_process(apr_proc_t * newproc,
- const char *progname,
- const char *const
- *args,
- const char *const *env,
- apr_procattr_t * attr,
- fcgid_proc_info *
- procinfo,
- apr_pool_t * p)
+ const char *progname,
+ const char *const
+ *args,
+ const char *const *env,
+ apr_procattr_t * attr,
+ fcgid_proc_info *
+ procinfo,
+ apr_pool_t * p)
{
- ap_unix_identity_t ugid;
+ ap_unix_identity_t ugid;
- if (!unixd_config.suexec_enabled
- || (procinfo->uid == (uid_t) - 1
- && procinfo->gid == (gid_t) - 1)) {
- return apr_proc_create(newproc, progname, args, env, attr, p);
- }
+ if (!unixd_config.suexec_enabled
+ || (procinfo->uid == (uid_t) - 1
+ && procinfo->gid == (gid_t) - 1)) {
+ return apr_proc_create(newproc, progname, args, env, attr, p);
+ }
- ugid.gid = procinfo->gid;
- ugid.uid = procinfo->uid;
- ugid.userdir = procinfo->userdir;
- return ap_unix_create_privileged_process(newproc, progname, args, env,
- attr, &ugid, p);
+ ugid.gid = procinfo->gid;
+ ugid.uid = procinfo->uid;
+ ugid.userdir = procinfo->userdir;
+ return ap_unix_create_privileged_process(newproc, progname, args, env,
+ attr, &ugid, p);
}
static apr_status_t socket_file_cleanup(void *theprocnode)
{
- fcgid_procnode *procnode = (fcgid_procnode *) theprocnode;
+ fcgid_procnode *procnode = (fcgid_procnode *) theprocnode;
- unlink(procnode->socket_path);
- return APR_SUCCESS;
+ unlink(procnode->socket_path);
+ return APR_SUCCESS;
}
static apr_status_t exec_setuid_cleanup(void *dummy)
{
- seteuid(0);
- setuid(unixd_config.user_id);
- return APR_SUCCESS;
+ seteuid(0);
+ setuid(unixd_config.user_id);
+ return APR_SUCCESS;
}
apr_status_t
proc_spawn_process(char *lpszwapper, fcgid_proc_info * procinfo,
- fcgid_procnode * procnode)
+ fcgid_procnode * procnode)
{
- server_rec *main_server = procinfo->main_server;
- apr_status_t rv = APR_SUCCESS;
- apr_file_t *file;
- int omask, retcode, unix_socket;
- char **proc_environ;
- struct sockaddr_un unix_addr;
- apr_procattr_t *procattr = NULL;
- char key_name[_POSIX_PATH_MAX];
- void *dummy;
- int argc;
- char *wargv[APACHE_ARG_MAX], *word; /* For wrapper */
- const char *tmp;
- char *argv[2];
+ server_rec *main_server = procinfo->main_server;
+ apr_status_t rv = APR_SUCCESS;
+ apr_file_t *file;
+ int omask, retcode, unix_socket;
+ char **proc_environ;
+ struct sockaddr_un unix_addr;
+ apr_procattr_t *procattr = NULL;
+ char key_name[_POSIX_PATH_MAX];
+ void *dummy;
+ int argc;
+ char *wargv[APACHE_ARG_MAX], *word; /* For wrapper */
+ const char *tmp;
+ char *argv[2];
- /* Build wrapper args */
- argc = 0;
- tmp = lpszwapper;
- while (1) {
- word = ap_getword_white(procnode->proc_pool, &tmp);
- if (word == NULL || *word == '\0')
- break;
- if (argc >= APACHE_ARG_MAX)
- break;
- wargv[argc++] = word;
- }
- wargv[argc] = NULL;
+ /* Build wrapper args */
+ argc = 0;
+ tmp = lpszwapper;
+ while (1) {
+ word = ap_getword_white(procnode->proc_pool, &tmp);
+ if (word == NULL || *word == '\0')
+ break;
+ if (argc >= APACHE_ARG_MAX)
+ break;
+ wargv[argc++] = word;
+ }
+ wargv[argc] = NULL;
- /* Initialize the variables */
- if (!g_inode_cginame_map) {
- apr_pool_create(&g_inode_cginame_map,
- procinfo->main_server->process->pconf);
- }
+ /* Initialize the variables */
+ if (!g_inode_cginame_map) {
+ apr_pool_create(&g_inode_cginame_map,
+ procinfo->main_server->process->pconf);
+ }
- if (!g_socket_dir)
- g_socket_dir = get_socketpath(procinfo->main_server);
- if (!g_inode_cginame_map || !g_socket_dir) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't cgi name map table");
- return APR_ENOMEM;
- }
+ if (!g_socket_dir)
+ g_socket_dir = get_socketpath(procinfo->main_server);
+ if (!g_inode_cginame_map || !g_socket_dir) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't cgi name map table");
+ return APR_ENOMEM;
+ }
- /*
- Create UNIX domain socket before spawn
- */
+ /*
+ Create UNIX domain socket before spawn
+ */
- /* Generate a UNIX domain socket file path */
- /* XXX It's nothing I can do if strlen(g_socket_dir) too long... */
- memset(&unix_addr, 0, sizeof(unix_addr));
- unix_addr.sun_family = AF_UNIX;
- apr_snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path) - 1,
- "%s/%d.%d", g_socket_dir, getpid(), g_process_counter++);
- strncpy(procnode->socket_path, unix_addr.sun_path,
- sizeof(procnode->socket_path) - 1);
+ /* Generate a UNIX domain socket file path */
+ /* XXX It's nothing I can do if strlen(g_socket_dir) too long... */
+ memset(&unix_addr, 0, sizeof(unix_addr));
+ unix_addr.sun_family = AF_UNIX;
+ apr_snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path) - 1,
+ "%s/%d.%d", g_socket_dir, getpid(), g_process_counter++);
+ strncpy(procnode->socket_path, unix_addr.sun_path,
+ sizeof(procnode->socket_path) - 1);
- /* Unlink the file just in case */
- unlink(unix_addr.sun_path);
+ /* Unlink the file just in case */
+ unlink(unix_addr.sun_path);
- /* Create the socket */
- if ((unix_socket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: couldn't create unix domain socket");
- return errno;
- }
+ /* Create the socket */
+ if ((unix_socket = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: couldn't create unix domain socket");
+ return errno;
+ }
- /* Unlink it when process exit */
- if (unixd_config.suexec_enabled) {
- apr_pool_cleanup_register(procnode->proc_pool,
- procnode, socket_file_cleanup,
- exec_setuid_cleanup);
- } else {
- apr_pool_cleanup_register(procnode->proc_pool,
- procnode, socket_file_cleanup,
- apr_pool_cleanup_null);
- }
+ /* Unlink it when process exit */
+ if (unixd_config.suexec_enabled) {
+ apr_pool_cleanup_register(procnode->proc_pool,
+ procnode, socket_file_cleanup,
+ exec_setuid_cleanup);
+ } else {
+ apr_pool_cleanup_register(procnode->proc_pool,
+ procnode, socket_file_cleanup,
+ apr_pool_cleanup_null);
+ }
- /* Bind the socket */
- omask = umask(0077);
- retcode = bind(unix_socket, (struct sockaddr *) &unix_addr,
- sizeof(unix_addr));
- umask(omask);
- if (retcode < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: couldn't bind unix domain socket %s",
- unix_addr.sun_path);
- close(unix_socket);
- return errno;
- }
+ /* Bind the socket */
+ omask = umask(0077);
+ retcode = bind(unix_socket, (struct sockaddr *) &unix_addr,
+ sizeof(unix_addr));
+ umask(omask);
+ if (retcode < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: couldn't bind unix domain socket %s",
+ unix_addr.sun_path);
+ close(unix_socket);
+ return errno;
+ }
- /* Listen the socket */
- if (listen(unix_socket, DEFAULT_FCGID_LISTENBACKLOG) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: couldn't listen on unix domain socket");
- close(unix_socket);
- return errno;
- }
+ /* Listen the socket */
+ if (listen(unix_socket, DEFAULT_FCGID_LISTENBACKLOG) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: couldn't listen on unix domain socket");
+ close(unix_socket);
+ return errno;
+ }
- /* Correct the file owner */
- if (!geteuid()) {
- if (chown(unix_addr.sun_path, unixd_config.user_id, -1) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
- "mod_fcgid: couldn't change owner of unix domain socket %s",
- unix_addr.sun_path);
- close(unix_socket);
- return errno;
- }
- }
+ /* Correct the file owner */
+ if (!geteuid()) {
+ if (chown(unix_addr.sun_path, unixd_config.user_id, -1) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, errno, main_server,
+ "mod_fcgid: couldn't change owner of unix domain socket %s",
+ unix_addr.sun_path);
+ close(unix_socket);
+ return errno;
+ }
+ }
- {
- int oldflags = fcntl(unix_socket, F_GETFD, 0);
+ {
+ int oldflags = fcntl(unix_socket, F_GETFD, 0);
- if (oldflags < 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: fcntl F_GETFD failed");
- close(unix_socket);
- return errno;
- }
+ if (oldflags < 0) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: fcntl F_GETFD failed");
+ close(unix_socket);
+ return errno;
+ }
- oldflags |= FD_CLOEXEC;
- if (fcntl(unix_socket, F_SETFD, oldflags) < 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: fcntl F_SETFD failed");
- close(unix_socket);
- return errno;
- }
- }
+ oldflags |= FD_CLOEXEC;
+ if (fcntl(unix_socket, F_SETFD, oldflags) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: fcntl F_SETFD failed");
+ close(unix_socket);
+ return errno;
+ }
+ }
- /* Build environment variables */
- proc_environ = ap_create_environment(procnode->proc_pool,
- procinfo->proc_environ);
- if (!proc_environ) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't build environment variables");
- close(unix_socket);
- return APR_ENOMEM;
- }
+ /* Build environment variables */
+ proc_environ = ap_create_environment(procnode->proc_pool,
+ procinfo->proc_environ);
+ if (!proc_environ) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't build environment variables");
+ close(unix_socket);
+ return APR_ENOMEM;
+ }
- /* Prepare the fork */
- if (!
- (procnode->proc_id =
- apr_pcalloc(procnode->proc_pool, sizeof(apr_proc_t)))
+ /* Prepare the fork */
+ if (!
+ (procnode->proc_id =
+ apr_pcalloc(procnode->proc_pool, sizeof(apr_proc_t)))
|| (rv =
- apr_procattr_create(&procattr, procnode->proc_pool)) != APR_SUCCESS
+ apr_procattr_create(&procattr, procnode->proc_pool)) != APR_SUCCESS
|| (rv =
- apr_procattr_child_err_set(procattr,
- procinfo->main_server->error_log,
- NULL)) != APR_SUCCESS
+ apr_procattr_child_err_set(procattr,
+ procinfo->main_server->error_log,
+ NULL)) != APR_SUCCESS
|| (rv =
- apr_procattr_child_out_set(procattr,
- procinfo->main_server->error_log,
- NULL)) != APR_SUCCESS
+ apr_procattr_child_out_set(procattr,
+ procinfo->main_server->error_log,
+ NULL)) != APR_SUCCESS
|| (rv =
- apr_procattr_dir_set(procattr,
- ap_make_dirstr_parent(procnode->proc_pool,
- (lpszwapper != NULL
- && lpszwapper[0] !=
- '\0') ? wargv[0] :
- procinfo->cgipath))) !=
+ apr_procattr_dir_set(procattr,
+ ap_make_dirstr_parent(procnode->proc_pool,
+ (lpszwapper != NULL
+ && lpszwapper[0] !=
+ '\0') ? wargv[0] :
+ procinfo->cgipath))) !=
APR_SUCCESS
|| (rv = apr_procattr_cmdtype_set(procattr, APR_PROGRAM)) != APR_SUCCESS
|| (rv =
- apr_os_file_put(&file, &unix_socket, 0,
- procnode->proc_pool)) != APR_SUCCESS
+ apr_os_file_put(&file, &unix_socket, 0,
+ procnode->proc_pool)) != APR_SUCCESS
|| (rv = apr_procattr_child_in_set(procattr, file, NULL)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
- "mod_fcgid: couldn't set child process attributes: %s",
- unix_addr.sun_path);
- close(unix_socket);
- return rv;
- }
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
+ "mod_fcgid: couldn't set child process attributes: %s",
+ unix_addr.sun_path);
+ close(unix_socket);
+ return rv;
+ }
- /* fork and exec now */
- if (lpszwapper != NULL && lpszwapper[0] != '\0') {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, procinfo->main_server,
- "mod_fcgid: call %s with wrapper %s",
- procinfo->cgipath, lpszwapper);
- if ((rv =
- fcgid_create_privileged_process(procnode->proc_id,
- wargv[0],
- (const char *const *) wargv,
- (const char *const *)
- proc_environ, procattr,
- procinfo,
- procnode->proc_pool)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
- "mod_fcgid: can't create wrapper process for %s",
- procinfo->cgipath);
- close(unix_socket);
- return rv;
- }
- } else {
- argv[0] = procinfo->cgipath;
- argv[1] = NULL;
- if ((rv =
- fcgid_create_privileged_process(procnode->proc_id,
- procinfo->cgipath,
- (const char *const *) argv,
- (const char *const *)
- proc_environ, procattr,
- procinfo,
- procnode->proc_pool)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
- "mod_fcgid: can't create process");
- close(unix_socket);
- return rv;
- }
- }
+ /* fork and exec now */
+ if (lpszwapper != NULL && lpszwapper[0] != '\0') {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, procinfo->main_server,
+ "mod_fcgid: call %s with wrapper %s",
+ procinfo->cgipath, lpszwapper);
+ if ((rv =
+ fcgid_create_privileged_process(procnode->proc_id,
+ wargv[0],
+ (const char *const *) wargv,
+ (const char *const *)
+ proc_environ, procattr,
+ procinfo,
+ procnode->proc_pool)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
+ "mod_fcgid: can't create wrapper process for %s",
+ procinfo->cgipath);
+ close(unix_socket);
+ return rv;
+ }
+ } else {
+ argv[0] = procinfo->cgipath;
+ argv[1] = NULL;
+ if ((rv =
+ fcgid_create_privileged_process(procnode->proc_id,
+ procinfo->cgipath,
+ (const char *const *) argv,
+ (const char *const *)
+ proc_environ, procattr,
+ procinfo,
+ procnode->proc_pool)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
+ "mod_fcgid: can't create process");
+ close(unix_socket);
+ return rv;
+ }
+ }
- /* Set the (deviceid, inode) -> fastcgi path map for log */
- apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX",
- procnode->inode, (unsigned long) procnode->deviceid);
- dummy = NULL;
- apr_pool_userdata_get((void **) &dummy, key_name, g_inode_cginame_map);
- if (!dummy) {
- /* Insert a new item if key not found */
- char *put_key = apr_psprintf(g_inode_cginame_map, "%lX%lX",
- procnode->inode,
- (unsigned long) procnode->deviceid);
- char *fcgipath = apr_psprintf(g_inode_cginame_map, "%s",
- procinfo->cgipath);
+ /* Set the (deviceid, inode) -> fastcgi path map for log */
+ apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX",
+ procnode->inode, (unsigned long) procnode->deviceid);
+ dummy = NULL;
+ apr_pool_userdata_get((void **) &dummy, key_name, g_inode_cginame_map);
+ if (!dummy) {
+ /* Insert a new item if key not found */
+ char *put_key = apr_psprintf(g_inode_cginame_map, "%lX%lX",
+ procnode->inode,
+ (unsigned long) procnode->deviceid);
+ char *fcgipath = apr_psprintf(g_inode_cginame_map, "%s",
+ procinfo->cgipath);
- if (put_key && fcgipath)
- apr_pool_userdata_set(fcgipath, put_key, NULL,
- g_inode_cginame_map);
- }
+ if (put_key && fcgipath)
+ apr_pool_userdata_set(fcgipath, put_key, NULL,
+ g_inode_cginame_map);
+ }
- /* Close socket before try to connect to it */
- close(unix_socket);
+ /* Close socket before try to connect to it */
+ close(unix_socket);
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
proc_kill_gracefully(fcgid_procnode * procnode, server_rec * main_server)
{
- /* su as root before sending kill signal, for suEXEC */
- apr_status_t rv;
+ /* su as root before sending kill signal, for suEXEC */
+ apr_status_t rv;
- if (unixd_config.suexec_enabled && seteuid(0) != 0) {
+ if (unixd_config.suexec_enabled && seteuid(0) != 0) {
- /* It's fatal error */
- kill(getpid(), SIGTERM);
- return APR_EACCES;
- }
- rv = apr_proc_kill(procnode->proc_id, SIGTERM);
- if (unixd_config.suexec_enabled && seteuid(unixd_config.user_id) != 0) {
- kill(getpid(), SIGTERM);
- return APR_EACCES;
- }
- return rv;
+ /* It's fatal error */
+ kill(getpid(), SIGTERM);
+ return APR_EACCES;
+ }
+ rv = apr_proc_kill(procnode->proc_id, SIGTERM);
+ if (unixd_config.suexec_enabled && seteuid(unixd_config.user_id) != 0) {
+ kill(getpid(), SIGTERM);
+ return APR_EACCES;
+ }
+ return rv;
}
apr_status_t proc_kill_force(fcgid_procnode * procnode,
- server_rec * main_server)
+ server_rec * main_server)
{
- apr_status_t rv;
+ apr_status_t rv;
- if (unixd_config.suexec_enabled && seteuid(0) != 0) {
+ if (unixd_config.suexec_enabled && seteuid(0) != 0) {
- /* It's fatal error */
- kill(getpid(), SIGTERM);
- return APR_EACCES;
- }
- rv = apr_proc_kill(procnode->proc_id, SIGKILL);
- if (unixd_config.suexec_enabled && seteuid(unixd_config.user_id) != 0) {
- kill(getpid(), SIGTERM);
- return APR_EACCES;
- }
- return rv;
+ /* It's fatal error */
+ kill(getpid(), SIGTERM);
+ return APR_EACCES;
+ }
+ rv = apr_proc_kill(procnode->proc_id, SIGKILL);
+ if (unixd_config.suexec_enabled && seteuid(unixd_config.user_id) != 0) {
+ kill(getpid(), SIGTERM);
+ return APR_EACCES;
+ }
+ return rv;
}
apr_status_t
proc_wait_process(server_rec * main_server, fcgid_procnode * procnode)
{
- apr_status_t rv;
- int exitcode;
- apr_exit_why_e exitwhy;
+ apr_status_t rv;
+ int exitcode;
+ apr_exit_why_e exitwhy;
- rv = apr_proc_wait(procnode->proc_id, &exitcode, &exitwhy, APR_NOWAIT);
- if (rv == APR_CHILD_DONE || rv == APR_EGENERAL) {
- /* Log why and how it die */
- proc_print_exit_info(procnode, exitcode, exitwhy, main_server);
+ rv = apr_proc_wait(procnode->proc_id, &exitcode, &exitwhy, APR_NOWAIT);
+ if (rv == APR_CHILD_DONE || rv == APR_EGENERAL) {
+ /* Log why and how it die */
+ proc_print_exit_info(procnode, exitcode, exitwhy, main_server);
- /* Register the death */
- register_termination(main_server, procnode);
+ /* Register the death */
+ register_termination(main_server, procnode);
- /* Destroy pool */
- apr_pool_destroy(procnode->proc_pool);
- procnode->proc_pool = NULL;
+ /* Destroy pool */
+ apr_pool_destroy(procnode->proc_pool);
+ procnode->proc_pool = NULL;
- return APR_CHILD_DONE;
- }
+ return APR_CHILD_DONE;
+ }
- return rv;
+ return rv;
}
static apr_status_t ipc_handle_cleanup(void *thesocket)
{
- fcgid_namedpipe_handle *handle_info =
- (fcgid_namedpipe_handle *) thesocket;
+ fcgid_namedpipe_handle *handle_info =
+ (fcgid_namedpipe_handle *) thesocket;
- if (handle_info) {
- if (handle_info->handle_socket != -1) {
- close(handle_info->handle_socket);
- handle_info->handle_socket = -1;
- }
- }
+ if (handle_info) {
+ if (handle_info->handle_socket != -1) {
+ close(handle_info->handle_socket);
+ handle_info->handle_socket = -1;
+ }
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
static apr_status_t set_socket_nonblock(int sd)
{
#ifndef BEOS
- int fd_flags;
+ int fd_flags;
- fd_flags = fcntl(sd, F_GETFL, 0);
+ fd_flags = fcntl(sd, F_GETFL, 0);
#if defined(O_NONBLOCK)
- fd_flags |= O_NONBLOCK;
+ fd_flags |= O_NONBLOCK;
#elif defined(O_NDELAY)
- fd_flags |= O_NDELAY;
+ fd_flags |= O_NDELAY;
#elif defined(FNDELAY)
- fd_flags |= FNDELAY;
+ fd_flags |= FNDELAY;
#else
#error Please teach APR how to make sockets non-blocking on your platform.
#endif
- if (fcntl(sd, F_SETFL, fd_flags) == -1) {
- return errno;
- }
+ if (fcntl(sd, F_SETFL, fd_flags) == -1) {
+ return errno;
+ }
#else
- int on = 1;
- if (setsockopt(sd, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int)) < 0)
- return errno;
-#endif /* BEOS */
- return APR_SUCCESS;
+ int on = 1;
+ if (setsockopt(sd, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(int)) < 0)
+ return errno;
+#endif /* BEOS */
+ return APR_SUCCESS;
}
apr_status_t
proc_connect_ipc(server_rec * main_server,
- fcgid_procnode * procnode, fcgid_ipc * ipc_handle)
+ fcgid_procnode * procnode, fcgid_ipc * ipc_handle)
{
- fcgid_namedpipe_handle *handle_info;
- struct sockaddr_un unix_addr;
- apr_status_t rv;
- apr_int32_t on = 1;
+ fcgid_namedpipe_handle *handle_info;
+ struct sockaddr_un unix_addr;
+ apr_status_t rv;
+ apr_int32_t on = 1;
- /* Alloc memory for unix domain socket */
- ipc_handle->ipc_handle_info
- = (fcgid_namedpipe_handle *) apr_pcalloc(ipc_handle->request->pool,
- sizeof
- (fcgid_namedpipe_handle));
- if (!ipc_handle->ipc_handle_info)
- return APR_ENOMEM;
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- handle_info->handle_socket = socket(AF_UNIX, SOCK_STREAM, 0);
- apr_pool_cleanup_register(ipc_handle->request->pool,
- handle_info, ipc_handle_cleanup,
- apr_pool_cleanup_null);
+ /* Alloc memory for unix domain socket */
+ ipc_handle->ipc_handle_info
+ = (fcgid_namedpipe_handle *) apr_pcalloc(ipc_handle->request->pool,
+ sizeof
+ (fcgid_namedpipe_handle));
+ if (!ipc_handle->ipc_handle_info)
+ return APR_ENOMEM;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ handle_info->handle_socket = socket(AF_UNIX, SOCK_STREAM, 0);
+ apr_pool_cleanup_register(ipc_handle->request->pool,
+ handle_info, ipc_handle_cleanup,
+ apr_pool_cleanup_null);
- /* Connect to fastcgi server */
- memset(&unix_addr, 0, sizeof(unix_addr));
- unix_addr.sun_family = AF_UNIX;
- strncpy(unix_addr.sun_path, procnode->socket_path,
- sizeof(unix_addr.sun_path) - 1);
+ /* Connect to fastcgi server */
+ memset(&unix_addr, 0, sizeof(unix_addr));
+ unix_addr.sun_family = AF_UNIX;
+ strncpy(unix_addr.sun_path, procnode->socket_path,
+ sizeof(unix_addr.sun_path) - 1);
- /* I am the only one who connecting the server
- So I don't have to worry about ECONNREFUSED(listen queue overflow) problem,
- and I will never retry on error */
- if (connect(handle_info->handle_socket, (struct sockaddr *) &unix_addr,
- sizeof(unix_addr)) < 0) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't connect unix domain socket: %s",
- procnode->socket_path);
- return APR_ECONNREFUSED;
- }
+ /* I am the only one who connecting the server
+ So I don't have to worry about ECONNREFUSED(listen queue overflow) problem,
+ and I will never retry on error */
+ if (connect(handle_info->handle_socket, (struct sockaddr *) &unix_addr,
+ sizeof(unix_addr)) < 0) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't connect unix domain socket: %s",
+ procnode->socket_path);
+ return APR_ECONNREFUSED;
+ }
- /* Set no delay option */
- setsockopt(handle_info->handle_socket, IPPROTO_TCP, TCP_NODELAY,
- (char *) &on, sizeof(on));
+ /* Set no delay option */
+ setsockopt(handle_info->handle_socket, IPPROTO_TCP, TCP_NODELAY,
+ (char *) &on, sizeof(on));
- /* Set nonblock option */
- if ((rv =
- set_socket_nonblock(handle_info->handle_socket)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, main_server,
- "mod_fcgid: can't set nonblock unix domain socket");
- return rv;
- }
+ /* Set nonblock option */
+ if ((rv =
+ set_socket_nonblock(handle_info->handle_socket)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, rv, main_server,
+ "mod_fcgid: can't set nonblock unix domain socket");
+ return rv;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t proc_close_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle)
+ fcgid_ipc * ipc_handle)
{
- apr_status_t rv;
+ apr_status_t rv;
- rv = apr_pool_cleanup_run(ipc_handle->request->pool,
- ipc_handle->ipc_handle_info,
- ipc_handle_cleanup);
- ipc_handle->ipc_handle_info = NULL;
- return rv;
+ rv = apr_pool_cleanup_run(ipc_handle->request->pool,
+ ipc_handle->ipc_handle_info,
+ ipc_handle_cleanup);
+ ipc_handle->ipc_handle_info = NULL;
+ return rv;
}
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)
{
- int retcode, unix_socket;
- fcgid_namedpipe_handle *handle_info;
- struct pollfd pollfds[1];
+ int retcode, unix_socket;
+ fcgid_namedpipe_handle *handle_info;
+ struct pollfd pollfds[1];
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- unix_socket = handle_info->handle_socket;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ unix_socket = handle_info->handle_socket;
- do {
- if ((retcode = read(unix_socket, (void *) buffer, *size)) > 0) {
- *size = retcode;
- return APR_SUCCESS;
- }
- } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
- if (retcode == -1 && !APR_STATUS_IS_EAGAIN(errno)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
- main_server,
- "mod_fcgid: read data from fastcgi server error");
- return errno;
- }
+ do {
+ if ((retcode = read(unix_socket, (void *) buffer, *size)) > 0) {
+ *size = retcode;
+ return APR_SUCCESS;
+ }
+ } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
+ if (retcode == -1 && !APR_STATUS_IS_EAGAIN(errno)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
+ main_server,
+ "mod_fcgid: read data from fastcgi server error");
+ return errno;
+ }
- /* I have to wait a while */
+ /* I have to wait a while */
- pollfds[0].fd = unix_socket;
- pollfds[0].events = POLLIN;
- do {
- retcode = poll(pollfds, 1, ipc_handle->communation_timeout * 1000);
- } while (retcode <= 0 && APR_STATUS_IS_EINTR(errno));
- if (retcode == -1) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
- main_server,
- "mod_fcgid: poll unix domain socket error");
- return errno;
- } else if (retcode == 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
- main_server,
- "mod_fcgid: read data timeout in %d seconds",
- ipc_handle->communation_timeout);
- return APR_ETIMEDOUT;
- }
+ pollfds[0].fd = unix_socket;
+ pollfds[0].events = POLLIN;
+ do {
+ retcode = poll(pollfds, 1, ipc_handle->communation_timeout * 1000);
+ } while (retcode <= 0 && APR_STATUS_IS_EINTR(errno));
+ if (retcode == -1) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
+ main_server,
+ "mod_fcgid: poll unix domain socket error");
+ return errno;
+ } else if (retcode == 0) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
+ main_server,
+ "mod_fcgid: read data timeout in %d seconds",
+ ipc_handle->communation_timeout);
+ return APR_ETIMEDOUT;
+ }
- do {
- if ((retcode = read(unix_socket, (void *) buffer, *size)) > 0) {
- *size = retcode;
- return APR_SUCCESS;
- }
- } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
+ do {
+ if ((retcode = read(unix_socket, (void *) buffer, *size)) > 0) {
+ *size = retcode;
+ return APR_SUCCESS;
+ }
+ } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
- if (retcode == 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
- main_server,
- "mod_fcgid: Read data error, fastcgi server has close connection");
- return APR_EPIPE;
- }
+ if (retcode == 0) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
+ main_server,
+ "mod_fcgid: Read data error, fastcgi server has close connection");
+ return APR_EPIPE;
+ }
- ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
- main_server,
- "mod_fcgid: read data from fastcgi server error.");
- return errno;
+ ap_log_error(APLOG_MARK, APLOG_WARNING, errno,
+ main_server,
+ "mod_fcgid: read data from fastcgi server error.");
+ return errno;
}
static apr_status_t socket_writev(fcgid_ipc * ipc_handle,
- struct iovec *vec, int nvec,
- int *writecnt)
+ struct iovec *vec, int nvec,
+ int *writecnt)
{
- int retcode, unix_socket;
- fcgid_namedpipe_handle *handle_info;
- struct pollfd pollfds[1];
+ int retcode, unix_socket;
+ fcgid_namedpipe_handle *handle_info;
+ struct pollfd pollfds[1];
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- unix_socket = handle_info->handle_socket;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ unix_socket = handle_info->handle_socket;
- /* Try nonblock write */
- do {
- if ((retcode = writev(unix_socket, vec, nvec)) > 0) {
- *writecnt = retcode;
- return APR_SUCCESS;
- }
- } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
- if (!APR_STATUS_IS_EAGAIN(errno))
- return errno;
+ /* Try nonblock write */
+ do {
+ if ((retcode = writev(unix_socket, vec, nvec)) > 0) {
+ *writecnt = retcode;
+ return APR_SUCCESS;
+ }
+ } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
+ if (!APR_STATUS_IS_EAGAIN(errno))
+ return errno;
- /* poll() */
- pollfds[0].fd = unix_socket;
- pollfds[0].events = POLLOUT;
- do {
- retcode = poll(pollfds, 1, ipc_handle->communation_timeout * 1000);
- } while (retcode <= 0 && APR_STATUS_IS_EINTR(errno));
- if (retcode == -1)
- return errno;
+ /* poll() */
+ pollfds[0].fd = unix_socket;
+ pollfds[0].events = POLLOUT;
+ do {
+ retcode = poll(pollfds, 1, ipc_handle->communation_timeout * 1000);
+ } while (retcode <= 0 && APR_STATUS_IS_EINTR(errno));
+ if (retcode == -1)
+ return errno;
- /* Write again */
- do {
- if ((retcode = writev(unix_socket, vec, nvec)) > 0) {
- *writecnt = retcode;
- return APR_SUCCESS;
- }
- } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
+ /* Write again */
+ do {
+ if ((retcode = writev(unix_socket, vec, nvec)) > 0) {
+ *writecnt = retcode;
+ return APR_SUCCESS;
+ }
+ } while (retcode == -1 && APR_STATUS_IS_EINTR(errno));
- if (retcode == 0) {
- ap_log_error(APLOG_MARK, APLOG_INFO, 0,
- ipc_handle->request->server,
- "mod_fcgid: Write data error, fastcgi server has close connection");
- return APR_EPIPE;
- }
+ if (retcode == 0) {
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0,
+ ipc_handle->request->server,
+ "mod_fcgid: Write data error, fastcgi server has close connection");
+ return APR_EPIPE;
+ }
- return errno;
+ return errno;
}
static apr_status_t writev_it_all(fcgid_ipc * ipc_handle,
- struct iovec *vec, int nvec)
+ struct iovec *vec, int nvec)
{
- apr_size_t bytes_written = 0;
- apr_status_t rv;
- apr_size_t len = 0;
- int i = 0;
- int writecnt = 0;
+ apr_size_t bytes_written = 0;
+ apr_status_t rv;
+ apr_size_t len = 0;
+ int i = 0;
+ int writecnt = 0;
- /* Calculate the total size */
- for (i = 0; i < nvec; i++) {
- len += vec[i].iov_len;
- }
+ /* Calculate the total size */
+ for (i = 0; i < nvec; i++) {
+ len += vec[i].iov_len;
+ }
- i = 0;
- while (bytes_written != len) {
- rv = socket_writev(ipc_handle, vec + i, nvec - i, &writecnt);
- if (rv != APR_SUCCESS)
- return rv;
- bytes_written += writecnt;
+ i = 0;
+ while (bytes_written != len) {
+ rv = socket_writev(ipc_handle, vec + i, nvec - i, &writecnt);
+ if (rv != APR_SUCCESS)
+ return rv;
+ bytes_written += writecnt;
- if (bytes_written < len) {
- /* Skip over the vectors that have already been written */
- apr_size_t cnt = vec[i].iov_len;
+ if (bytes_written < len) {
+ /* Skip over the vectors that have already been written */
+ apr_size_t cnt = vec[i].iov_len;
- while (writecnt >= cnt && i + 1 < nvec) {
- i++;
- cnt += vec[i].iov_len;
- }
+ while (writecnt >= cnt && i + 1 < nvec) {
+ i++;
+ cnt += vec[i].iov_len;
+ }
- if (writecnt < cnt) {
- /* Handle partial write of vec i */
- vec[i].iov_base = (char *) vec[i].iov_base +
- (vec[i].iov_len - (cnt - writecnt));
- vec[i].iov_len = cnt - writecnt;
- }
- }
- }
+ if (writecnt < cnt) {
+ /* Handle partial write of vec i */
+ vec[i].iov_base = (char *) vec[i].iov_base +
+ (vec[i].iov_len - (cnt - writecnt));
+ vec[i].iov_len = cnt - writecnt;
+ }
+ }
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
#define FCGID_VEC_COUNT 8
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 rv;
- struct iovec vec[FCGID_VEC_COUNT];
- int nvec = 0;
- apr_bucket *e;
+ apr_status_t rv;
+ struct iovec vec[FCGID_VEC_COUNT];
+ int nvec = 0;
+ apr_bucket *e;
- for (e = APR_BRIGADE_FIRST(output_brigade);
- e != APR_BRIGADE_SENTINEL(output_brigade);
- e = APR_BUCKET_NEXT(e)) {
- /* Read bucket */
- if ((rv = apr_bucket_read(e, (const char **) &vec[nvec].iov_base,
- &vec[nvec].iov_len,
- APR_BLOCK_READ)) != APR_SUCCESS)
- return rv;
+ for (e = APR_BRIGADE_FIRST(output_brigade);
+ e != APR_BRIGADE_SENTINEL(output_brigade);
+ e = APR_BUCKET_NEXT(e)) {
+ /* Read bucket */
+ if ((rv = apr_bucket_read(e, (const char **) &vec[nvec].iov_base,
+ &vec[nvec].iov_len,
+ APR_BLOCK_READ)) != APR_SUCCESS)
+ return rv;
- if (nvec == (FCGID_VEC_COUNT - 1)) {
- /* It's time to write now */
- if ((rv =
- writev_it_all(ipc_handle, vec,
- FCGID_VEC_COUNT)) != APR_SUCCESS)
- return rv;
- nvec = 0;
- } else
- nvec++;
- }
+ if (nvec == (FCGID_VEC_COUNT - 1)) {
+ /* It's time to write now */
+ if ((rv =
+ writev_it_all(ipc_handle, vec,
+ FCGID_VEC_COUNT)) != APR_SUCCESS)
+ return rv;
+ nvec = 0;
+ } else
+ nvec++;
+ }
- /* There are something left */
- if (nvec != 0) {
- if ((rv = writev_it_all(ipc_handle, vec, nvec)) != APR_SUCCESS)
- return rv;
- }
+ /* There are something left */
+ if (nvec != 0) {
+ if ((rv = writev_it_all(ipc_handle, vec, nvec)) != APR_SUCCESS)
+ return rv;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
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)
{
- char *cgipath = NULL;
- char *diewhy = NULL;
- char signal_info[HUGE_STRING_LEN];
- char key_name[_POSIX_PATH_MAX];
- int signum = exitcode;
+ char *cgipath = NULL;
+ char *diewhy = NULL;
+ char signal_info[HUGE_STRING_LEN];
+ char key_name[_POSIX_PATH_MAX];
+ int signum = exitcode;
- memset(signal_info, 0, HUGE_STRING_LEN);
+ memset(signal_info, 0, HUGE_STRING_LEN);
- /* Get the file name infomation base on inode and deviceid */
- apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX",
- procnode->inode, (unsigned long) procnode->deviceid);
- apr_pool_userdata_get((void **) &cgipath, key_name,
- g_inode_cginame_map);
+ /* Get the file name infomation base on inode and deviceid */
+ apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX",
+ procnode->inode, (unsigned long) procnode->deviceid);
+ apr_pool_userdata_get((void **) &cgipath, key_name,
+ g_inode_cginame_map);
- /* Reasons to exit */
- switch (procnode->diewhy) {
- case FCGID_DIE_KILLSELF:
- diewhy = "normal exit";
- break;
- case FCGID_DIE_IDLE_TIMEOUT:
- diewhy = "idle timeout";
- break;
- case FCGID_DIE_LIFETIME_EXPIRED:
- diewhy = "lifetime expired";
- break;
- case FCGID_DIE_BUSY_TIMEOUT:
- diewhy = "busy timeout";
- break;
- case FCGID_DIE_CONNECT_ERROR:
- diewhy = "connect error";
- break;
- case FCGID_DIE_COMM_ERROR:
- diewhy = "communication error";
- break;
- case FCGID_DIE_SHUTDOWN:
- diewhy = "shutting down";
- break;
- default:
- diewhy = "unknow";
- }
+ /* Reasons to exit */
+ switch (procnode->diewhy) {
+ case FCGID_DIE_KILLSELF:
+ diewhy = "normal exit";
+ break;
+ case FCGID_DIE_IDLE_TIMEOUT:
+ diewhy = "idle timeout";
+ break;
+ case FCGID_DIE_LIFETIME_EXPIRED:
+ diewhy = "lifetime expired";
+ break;
+ case FCGID_DIE_BUSY_TIMEOUT:
+ diewhy = "busy timeout";
+ break;
+ case FCGID_DIE_CONNECT_ERROR:
+ diewhy = "connect error";
+ break;
+ case FCGID_DIE_COMM_ERROR:
+ diewhy = "communication error";
+ break;
+ case FCGID_DIE_SHUTDOWN:
+ diewhy = "shutting down";
+ break;
+ default:
+ diewhy = "unknow";
+ }
- /* Get signal info */
- if (APR_PROC_CHECK_SIGNALED(exitwhy)) {
- switch (signum) {
- case SIGTERM:
- case SIGHUP:
- case AP_SIG_GRACEFUL:
- case SIGKILL:
- apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
- "get stop signal %d", signum);
- break;
+ /* Get signal info */
+ if (APR_PROC_CHECK_SIGNALED(exitwhy)) {
+ switch (signum) {
+ case SIGTERM:
+ case SIGHUP:
+ case AP_SIG_GRACEFUL:
+ case SIGKILL:
+ apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
+ "get stop signal %d", signum);
+ break;
- default:
- if (APR_PROC_CHECK_CORE_DUMP(exitwhy)) {
- apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
- "get signal %d, possible coredump generated",
- signum);
- } else {
- apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
- "get unexpected signal %d", signum);
- }
- }
- } else if (APR_PROC_CHECK_EXIT(exitwhy)) {
- apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
- "terminated by calling exit(), return code: %d",
- exitcode);
- if (procnode->diewhy == FCGID_DIE_CONNECT_ERROR)
- diewhy = "server exited";
- }
+ default:
+ if (APR_PROC_CHECK_CORE_DUMP(exitwhy)) {
+ apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
+ "get signal %d, possible coredump generated",
+ signum);
+ } else {
+ apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
+ "get unexpected signal %d", signum);
+ }
+ }
+ } else if (APR_PROC_CHECK_EXIT(exitwhy)) {
+ apr_snprintf(signal_info, HUGE_STRING_LEN - 1,
+ "terminated by calling exit(), return code: %d",
+ exitcode);
+ if (procnode->diewhy == FCGID_DIE_CONNECT_ERROR)
+ diewhy = "server exited";
+ }
- /* Print log now */
- if (cgipath)
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
- "mod_fcgid: process %s(%d) exit(%s), %s",
- cgipath, procnode->proc_id->pid, diewhy, signal_info);
- else
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
- "mod_fcgid: can't get cgi name while exiting, exitcode: %d",
- exitcode);
+ /* Print log now */
+ if (cgipath)
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
+ "mod_fcgid: process %s(%d) exit(%s), %s",
+ cgipath, procnode->proc_id->pid, diewhy, signal_info);
+ else
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, main_server,
+ "mod_fcgid: can't get cgi name while exiting, exitcode: %d",
+ exitcode);
}
diff --git a/mod_fcgid/arch/unix/fcgid_proctbl_unix.c b/mod_fcgid/arch/unix/fcgid_proctbl_unix.c
index 852c0c4..c348e1f 100644
--- a/mod_fcgid/arch/unix/fcgid_proctbl_unix.c
+++ b/mod_fcgid/arch/unix/fcgid_proctbl_unix.c
@@ -10,13 +10,13 @@
static apr_shm_t *g_sharemem = NULL;
static apr_global_mutex_t *g_sharelock = NULL;
char g_sharelock_name[L_tmpnam];
-static fcgid_procnode *g_proc_array = NULL; /* Contain all process slot */
-static fcgid_procnode *g_free_list_header = NULL; /* Attach to no process list */
-static fcgid_procnode *g_busy_list_header = NULL; /* Attach to a working process list */
-static fcgid_procnode *g_idle_list_header = NULL; /* Attach to an idle process list */
-static fcgid_procnode *g_error_list_header = NULL; /* Attach to an error process list */
+static fcgid_procnode *g_proc_array = NULL; /* Contain all process slot */
+static fcgid_procnode *g_free_list_header = NULL; /* Attach to no process list */
+static fcgid_procnode *g_busy_list_header = NULL; /* Attach to a working process list */
+static fcgid_procnode *g_idle_list_header = NULL; /* Attach to an idle process list */
+static fcgid_procnode *g_error_list_header = NULL; /* Attach to an error process list */
static fcgid_share *_global_memory = NULL;
-static fcgid_global_share *g_global_share = NULL; /* global information */
+static fcgid_global_share *g_global_share = NULL; /* global information */
static size_t g_table_size = FCGID_PROC_TABLE_SIZE;
/* apr version 0.x not support apr_shm_remove, I have to copy it from apr version 1.x */
@@ -46,256 +46,256 @@
static apr_status_t apr_shm_remove(const char *filename, apr_pool_t * pool)
{
#if APR_USE_SHMEM_SHMGET
- apr_status_t status;
- apr_file_t *file;
- key_t shmkey;
- int shmid;
+ apr_status_t status;
+ apr_file_t *file;
+ key_t shmkey;
+ int shmid;
#endif
#if APR_USE_SHMEM_MMAP_TMP
- return apr_file_remove(filename, pool);
+ return apr_file_remove(filename, pool);
#endif
#if APR_USE_SHMEM_MMAP_SHM
- if (shm_unlink(filename) == -1) {
- return errno;
- }
- return APR_SUCCESS;
+ if (shm_unlink(filename) == -1) {
+ return errno;
+ }
+ return APR_SUCCESS;
#endif
#if APR_USE_SHMEM_SHMGET
- /* Presume that the file already exists; just open for writing */
- status = apr_file_open(&file, filename, APR_WRITE,
- APR_OS_DEFAULT, pool);
- if (status) {
- return status;
- }
+ /* Presume that the file already exists; just open for writing */
+ status = apr_file_open(&file, filename, APR_WRITE,
+ APR_OS_DEFAULT, pool);
+ if (status) {
+ return status;
+ }
- /* ftok() (on solaris at least) requires that the file actually
- * exist before calling ftok(). */
- shmkey = ftok(filename, 1);
- if (shmkey == (key_t) - 1) {
- goto shm_remove_failed;
- }
+ /* ftok() (on solaris at least) requires that the file actually
+ * exist before calling ftok(). */
+ shmkey = ftok(filename, 1);
+ if (shmkey == (key_t) - 1) {
+ goto shm_remove_failed;
+ }
- apr_file_close(file);
+ apr_file_close(file);
- if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
- goto shm_remove_failed;
- }
+ if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
+ goto shm_remove_failed;
+ }
- /* Indicate that the segment is to be destroyed as soon
- * as all processes have detached. This also disallows any
- * new attachments to the segment. */
- if (shmctl(shmid, IPC_RMID, NULL) == -1) {
- goto shm_remove_failed;
- }
- return apr_file_remove(filename, pool);
+ /* Indicate that the segment is to be destroyed as soon
+ * as all processes have detached. This also disallows any
+ * new attachments to the segment. */
+ if (shmctl(shmid, IPC_RMID, NULL) == -1) {
+ goto shm_remove_failed;
+ }
+ return apr_file_remove(filename, pool);
shm_remove_failed:
- status = errno;
- /* ensure the file has been removed anyway. */
- apr_file_remove(filename, pool);
- return status;
+ status = errno;
+ /* ensure the file has been removed anyway. */
+ apr_file_remove(filename, pool);
+ return status;
#endif
- /* No support for anonymous shm */
- return APR_ENOTIMPL;
+ /* No support for anonymous shm */
+ return APR_ENOTIMPL;
}
-#endif /* APR_MAJOR_VERSION<1 */
+#endif /* APR_MAJOR_VERSION<1 */
apr_status_t
proctable_post_config(server_rec * main_server, apr_pool_t * configpool)
{
- size_t shmem_size = sizeof(fcgid_share);
- fcgid_procnode *ptmpnode = NULL;
- int i;
- apr_status_t rv;
- const char *fname;
+ size_t shmem_size = sizeof(fcgid_share);
+ fcgid_procnode *ptmpnode = NULL;
+ int i;
+ apr_status_t rv;
+ const char *fname;
- fname = get_shmpath(main_server);
+ fname = get_shmpath(main_server);
- /* Remove share memory first */
- apr_shm_remove(fname, main_server->process->pconf);
+ /* Remove share memory first */
+ apr_shm_remove(fname, main_server->process->pconf);
- /* Create share memory */
- if ((rv = apr_shm_create(&g_sharemem, shmem_size, fname,
- main_server->process->pconf)) != APR_SUCCESS)
- {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't create share memory for size %zu byte",
- shmem_size);
- exit(1);
- }
- if ((_global_memory = apr_shm_baseaddr_get(g_sharemem)) == NULL) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(),
- main_server,
- "mod_fcgid: Can't get base address of share memory");
- exit(1);
- }
+ /* Create share memory */
+ if ((rv = apr_shm_create(&g_sharemem, shmem_size, fname,
+ main_server->process->pconf)) != APR_SUCCESS)
+ {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't create share memory for size %zu byte",
+ shmem_size);
+ exit(1);
+ }
+ if ((_global_memory = apr_shm_baseaddr_get(g_sharemem)) == NULL) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: Can't get base address of share memory");
+ exit(1);
+ }
- /* Create global mutex */
- if ((rv =
- apr_global_mutex_create(&g_sharelock, tmpnam(g_sharelock_name),
- APR_LOCK_DEFAULT,
- main_server->process->pconf)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't create global mutex");
- exit(1);
- }
- if ((rv = unixd_set_global_mutex_perms(g_sharelock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't set global mutex perms");
- exit(1);
- }
+ /* Create global mutex */
+ if ((rv =
+ apr_global_mutex_create(&g_sharelock, tmpnam(g_sharelock_name),
+ APR_LOCK_DEFAULT,
+ main_server->process->pconf)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't create global mutex");
+ exit(1);
+ }
+ if ((rv = unixd_set_global_mutex_perms(g_sharelock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't set global mutex perms");
+ exit(1);
+ }
- memset(_global_memory, 0, shmem_size);
- g_proc_array = _global_memory->procnode_array;
- g_global_share = &_global_memory->global;
+ memset(_global_memory, 0, shmem_size);
+ g_proc_array = _global_memory->procnode_array;
+ g_global_share = &_global_memory->global;
- g_global_share->must_exit = 0;
+ g_global_share->must_exit = 0;
- /* Init the array */
- g_idle_list_header = g_proc_array;
- g_busy_list_header = g_idle_list_header + 1;
- g_error_list_header = g_busy_list_header + 1;
- g_free_list_header = g_error_list_header + 1;
- ptmpnode = g_free_list_header;
- for (i = 0; i < FCGID_MAX_APPLICATION; i++) {
- ptmpnode->next_index = ptmpnode - g_proc_array + 1;
- ptmpnode++;
- }
+ /* Init the array */
+ g_idle_list_header = g_proc_array;
+ g_busy_list_header = g_idle_list_header + 1;
+ g_error_list_header = g_busy_list_header + 1;
+ g_free_list_header = g_error_list_header + 1;
+ ptmpnode = g_free_list_header;
+ for (i = 0; i < FCGID_MAX_APPLICATION; i++) {
+ ptmpnode->next_index = ptmpnode - g_proc_array + 1;
+ ptmpnode++;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
proctable_child_init(server_rec * main_server, apr_pool_t * configpool)
{
- apr_status_t rv;
+ apr_status_t rv;
- if ((rv = apr_global_mutex_child_init(&g_sharelock,
- g_sharelock_name,
- main_server->process->pconf)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: apr_global_mutex_child_init error");
- exit(1);
- }
+ if ((rv = apr_global_mutex_child_init(&g_sharelock,
+ g_sharelock_name,
+ main_server->process->pconf)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: apr_global_mutex_child_init error");
+ exit(1);
+ }
- return rv;
+ return rv;
}
apr_status_t proctable_lock_table(void)
{
- return apr_global_mutex_lock(g_sharelock);
+ return apr_global_mutex_lock(g_sharelock);
}
apr_status_t proctable_unlock_table(void)
{
- return apr_global_mutex_unlock(g_sharelock);
+ return apr_global_mutex_unlock(g_sharelock);
}
fcgid_procnode *proctable_get_free_list(void)
{
- return g_free_list_header;
+ return g_free_list_header;
}
fcgid_procnode *proctable_get_busy_list(void)
{
- return g_busy_list_header;
+ return g_busy_list_header;
}
fcgid_procnode *proctable_get_idle_list(void)
{
- return g_idle_list_header;
+ return g_idle_list_header;
}
fcgid_procnode *proctable_get_table_array(void)
{
- return g_proc_array;
+ return g_proc_array;
}
fcgid_procnode *proctable_get_error_list(void)
{
- return g_error_list_header;
+ return g_error_list_header;
}
fcgid_global_share *proctable_get_globalshare(void)
{
- return g_global_share;
+ return g_global_share;
}
size_t proctable_get_table_size(void)
{
- return g_table_size;
+ return g_table_size;
}
void safe_lock(server_rec * main_server)
{
- apr_status_t rv;
+ apr_status_t rv;
- if (g_global_share->must_exit) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, 0, main_server,
- "mod_fcgid: server is restarted, %d must exit",
- getpid());
- kill(getpid(), SIGTERM);
- }
+ if (g_global_share->must_exit) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, 0, main_server,
+ "mod_fcgid: server is restarted, %d must exit",
+ getpid());
+ kill(getpid(), SIGTERM);
+ }
- /* Lock error is a fatal error */
- if ((rv = proctable_lock_table()) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't get lock, pid: %d", getpid());
- exit(1);
- }
+ /* Lock error is a fatal error */
+ if ((rv = proctable_lock_table()) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't get lock, pid: %d", getpid());
+ exit(1);
+ }
}
void safe_unlock(server_rec * main_server)
{
- /* Lock error is a fatal error */
- apr_status_t rv;
+ /* Lock error is a fatal error */
+ apr_status_t rv;
- if ((rv = proctable_unlock_table()) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't unlock, pid: %d", getpid());
- exit(1);
- }
+ if ((rv = proctable_unlock_table()) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't unlock, pid: %d", getpid());
+ exit(1);
+ }
}
void proctable_print_debug_info(server_rec * main_server)
{
- int freecount = 0;
- fcgid_procnode *current_node;
+ int freecount = 0;
+ fcgid_procnode *current_node;
- for (current_node = &g_proc_array[g_free_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index])
- freecount++;
+ for (current_node = &g_proc_array[g_free_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index])
+ freecount++;
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: total node count: %d, free node count: %d",
- FCGID_MAX_APPLICATION, freecount);
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: total node count: %d, free node count: %d",
+ FCGID_MAX_APPLICATION, freecount);
- for (current_node = &g_proc_array[g_idle_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: idle node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_idle_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: idle node index: %d",
+ current_node - g_proc_array);
+ }
- for (current_node = &g_proc_array[g_busy_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: busy node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_busy_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: busy node index: %d",
+ current_node - g_proc_array);
+ }
- for (current_node = &g_proc_array[g_error_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: error node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_error_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: error node index: %d",
+ current_node - g_proc_array);
+ }
}
diff --git a/mod_fcgid/arch/win32/fcgid_pm_win.c b/mod_fcgid/arch/win32/fcgid_pm_win.c
index 1fa43e2..18054f2 100644
--- a/mod_fcgid/arch/win32/fcgid_pm_win.c
+++ b/mod_fcgid/arch/win32/fcgid_pm_win.c
@@ -17,277 +17,277 @@
static void *APR_THREAD_FUNC wakeup_thread(apr_thread_t * thd, void *data)
{
- while (!g_must_exit) {
- /* Wake up every second to check g_must_exit flag */
- int i;
+ while (!g_must_exit) {
+ /* Wake up every second to check g_must_exit flag */
+ int i;
- for (i = 0; i < g_wakeup_timeout; i++) {
- if (g_must_exit)
- break;
- apr_sleep(apr_time_from_sec(1));
- }
+ for (i = 0; i < g_wakeup_timeout; i++) {
+ if (g_must_exit)
+ break;
+ apr_sleep(apr_time_from_sec(1));
+ }
- /* Send a wake up message to procmgr_peek_cmd() */
- if (!g_must_exit && g_msgqueue)
- apr_queue_trypush(g_msgqueue, NULL);
- }
- return NULL;
+ /* Send a wake up message to procmgr_peek_cmd() */
+ if (!g_must_exit && g_msgqueue)
+ apr_queue_trypush(g_msgqueue, NULL);
+ }
+ return NULL;
}
static void *APR_THREAD_FUNC worker_thread(apr_thread_t * thd, void *data)
{
- server_rec *main_server = data;
+ server_rec *main_server = data;
- pm_main(main_server, main_server->process->pconf);
- return NULL;
+ pm_main(main_server, main_server->process->pconf);
+ return NULL;
}
apr_status_t
procmgr_post_config(server_rec * main_server, apr_pool_t * pconf)
{
- apr_status_t rv;
- int error_scan_interval, busy_scan_interval, idle_scan_interval;
+ apr_status_t rv;
+ int error_scan_interval, busy_scan_interval, idle_scan_interval;
- /* Initialize spawn controler */
- spawn_control_init(main_server, pconf);
+ /* Initialize spawn controler */
+ spawn_control_init(main_server, pconf);
- /* Create a message queues */
- if ((rv = apr_queue_create(&g_msgqueue, FCGID_MSGQUEUE_SIZE,
- pconf)) != APR_SUCCESS
- || (rv = apr_queue_create(&g_notifyqueue, FCGID_MSGQUEUE_SIZE,
- pconf)) != APR_SUCCESS) {
- /* Fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't create message queue");
- exit(1);
- }
+ /* Create a message queues */
+ if ((rv = apr_queue_create(&g_msgqueue, FCGID_MSGQUEUE_SIZE,
+ pconf)) != APR_SUCCESS
+ || (rv = apr_queue_create(&g_notifyqueue, FCGID_MSGQUEUE_SIZE,
+ pconf)) != APR_SUCCESS) {
+ /* Fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't create message queue");
+ exit(1);
+ }
- /* Create request lock */
- if ((rv = apr_thread_mutex_create(&g_reqlock,
- APR_THREAD_MUTEX_DEFAULT,
- pconf)) != APR_SUCCESS) {
- /* Fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't create request mutex");
- exit(1);
- }
+ /* Create request lock */
+ if ((rv = apr_thread_mutex_create(&g_reqlock,
+ APR_THREAD_MUTEX_DEFAULT,
+ pconf)) != APR_SUCCESS) {
+ /* Fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't create request mutex");
+ exit(1);
+ }
- /* Calculate procmgr_peek_cmd wake up interval */
- error_scan_interval = get_error_scan_interval(main_server);
- busy_scan_interval = get_busy_scan_interval(main_server);
- idle_scan_interval = get_idle_scan_interval(main_server);
- g_wakeup_timeout = min(error_scan_interval, busy_scan_interval);
- g_wakeup_timeout = min(idle_scan_interval, g_wakeup_timeout);
- if (g_wakeup_timeout == 0)
- g_wakeup_timeout = 1; /* Make it reasonable */
+ /* Calculate procmgr_peek_cmd wake up interval */
+ error_scan_interval = get_error_scan_interval(main_server);
+ busy_scan_interval = get_busy_scan_interval(main_server);
+ idle_scan_interval = get_idle_scan_interval(main_server);
+ g_wakeup_timeout = min(error_scan_interval, busy_scan_interval);
+ g_wakeup_timeout = min(idle_scan_interval, g_wakeup_timeout);
+ if (g_wakeup_timeout == 0)
+ g_wakeup_timeout = 1; /* Make it reasonable */
- /* Create process manager worker thread */
- if ((rv = apr_thread_create(&g_thread, NULL, worker_thread,
- main_server, pconf)) != APR_SUCCESS) {
- /* It's a fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't create process manager thread");
- exit(1);
- }
+ /* Create process manager worker thread */
+ if ((rv = apr_thread_create(&g_thread, NULL, worker_thread,
+ main_server, pconf)) != APR_SUCCESS) {
+ /* It's a fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't create process manager thread");
+ exit(1);
+ }
- /* Create wake up thread */
- /* XXX If there was a function such like apr_queue_pop_timedwait(),
- then I don't need such an ugly thread to do the wake up job */
- if ((rv = apr_thread_create(&g_wakeup_thread, NULL, wakeup_thread,
- NULL, pconf)) != APR_SUCCESS) {
- /* It's a fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't create wake up thread");
- exit(1);
- }
+ /* Create wake up thread */
+ /* XXX If there was a function such like apr_queue_pop_timedwait(),
+ then I don't need such an ugly thread to do the wake up job */
+ if ((rv = apr_thread_create(&g_wakeup_thread, NULL, wakeup_thread,
+ NULL, pconf)) != APR_SUCCESS) {
+ /* It's a fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't create wake up thread");
+ exit(1);
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
void procmgr_init_spawn_cmd(fcgid_command * command, request_rec * r,
- const char *argv0, dev_t deviceid,
- apr_ino_t inode, apr_size_t share_grp_id)
+ const char *argv0, dev_t deviceid,
+ apr_ino_t inode, apr_size_t share_grp_id)
{
- server_rec *main_server = r->server;
- apr_table_t *initenv;
- fcgid_wrapper_conf *wrapperconf;
- const apr_array_header_t *initenv_arr;
- const apr_table_entry_t *initenv_entry;
- int i;
+ server_rec *main_server = r->server;
+ apr_table_t *initenv;
+ fcgid_wrapper_conf *wrapperconf;
+ const apr_array_header_t *initenv_arr;
+ const apr_table_entry_t *initenv_entry;
+ int i;
- memset(command, 0, sizeof(*command));
+ memset(command, 0, sizeof(*command));
- /* Environment variables */
- initenv = get_default_env_vars(r);
- if (initenv) {
- initenv_arr = apr_table_elts(initenv);
- initenv_entry = (apr_table_entry_t *) initenv_arr->elts;
- if (initenv_arr->nelts > INITENV_CNT)
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: too much environment variables, Please increase INITENV_CNT in fcgid_pm.h and recompile module mod_fcgid");
- for (i = 0; i < initenv_arr->nelts && i < INITENV_CNT; ++i) {
- if (initenv_entry[i].key == NULL
- || initenv_entry[i].key[0] == '\0')
- break;
- strncpy(command->initenv_key[i], initenv_entry[i].key,
- INITENV_KEY_LEN);
- command->initenv_key[i][INITENV_KEY_LEN - 1] = '\0';
- strncpy(command->initenv_val[i], initenv_entry[i].val,
- INITENV_VAL_LEN);
- command->initenv_val[i][INITENV_VAL_LEN - 1] = '\0';
- }
- }
+ /* Environment variables */
+ initenv = get_default_env_vars(r);
+ if (initenv) {
+ initenv_arr = apr_table_elts(initenv);
+ initenv_entry = (apr_table_entry_t *) initenv_arr->elts;
+ if (initenv_arr->nelts > INITENV_CNT)
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: too much environment variables, Please increase INITENV_CNT in fcgid_pm.h and recompile module mod_fcgid");
+ for (i = 0; i < initenv_arr->nelts && i < INITENV_CNT; ++i) {
+ if (initenv_entry[i].key == NULL
+ || initenv_entry[i].key[0] == '\0')
+ break;
+ strncpy(command->initenv_key[i], initenv_entry[i].key,
+ INITENV_KEY_LEN);
+ command->initenv_key[i][INITENV_KEY_LEN - 1] = '\0';
+ strncpy(command->initenv_val[i], initenv_entry[i].val,
+ INITENV_VAL_LEN);
+ command->initenv_val[i][INITENV_VAL_LEN - 1] = '\0';
+ }
+ }
- strncpy(command->cgipath, argv0, _POSIX_PATH_MAX);
- command->cgipath[_POSIX_PATH_MAX - 1] = '\0';
- command->deviceid = deviceid;
- command->inode = inode;
- command->share_grp_id = share_grp_id;
- command->uid = (uid_t) - 1;
- command->gid = (gid_t) - 1;
- command->userdir = 0;
+ strncpy(command->cgipath, argv0, _POSIX_PATH_MAX);
+ command->cgipath[_POSIX_PATH_MAX - 1] = '\0';
+ command->deviceid = deviceid;
+ command->inode = inode;
+ command->share_grp_id = share_grp_id;
+ command->uid = (uid_t) - 1;
+ command->gid = (gid_t) - 1;
+ command->userdir = 0;
- /* Update fcgid_command with wrapper info */
- command->wrapperpath[0] = '\0';
- if ((wrapperconf = get_wrapper_info(argv0, r))) {
- strncpy(command->wrapperpath, wrapperconf->args, _POSIX_PATH_MAX);
- command->wrapperpath[_POSIX_PATH_MAX - 1] = '\0';
- command->deviceid = wrapperconf->deviceid;
- command->inode = wrapperconf->inode;
- command->share_grp_id = wrapperconf->share_group_id;
- }
+ /* Update fcgid_command with wrapper info */
+ command->wrapperpath[0] = '\0';
+ if ((wrapperconf = get_wrapper_info(argv0, r))) {
+ strncpy(command->wrapperpath, wrapperconf->args, _POSIX_PATH_MAX);
+ command->wrapperpath[_POSIX_PATH_MAX - 1] = '\0';
+ command->deviceid = wrapperconf->deviceid;
+ command->inode = wrapperconf->inode;
+ command->share_grp_id = wrapperconf->share_group_id;
+ }
}
apr_status_t procmgr_post_spawn_cmd(fcgid_command * command,
- request_rec * r)
+ request_rec * r)
{
- server_rec *main_server = r->server;
+ server_rec *main_server = r->server;
- if (g_thread && g_msgqueue && !g_must_exit
- && g_reqlock && g_notifyqueue) {
- apr_status_t rv;
+ if (g_thread && g_msgqueue && !g_must_exit
+ && g_reqlock && g_notifyqueue) {
+ apr_status_t rv;
- /*
- Prepare the message send to another thread
- destroy the message if I can't push to message
- */
- fcgid_command *postcmd =
- (fcgid_command *) malloc(sizeof(fcgid_command));
- if (!postcmd)
- return APR_ENOMEM;
- memcpy(postcmd, command, sizeof(*command));
+ /*
+ Prepare the message send to another thread
+ destroy the message if I can't push to message
+ */
+ fcgid_command *postcmd =
+ (fcgid_command *) malloc(sizeof(fcgid_command));
+ if (!postcmd)
+ return APR_ENOMEM;
+ memcpy(postcmd, command, sizeof(*command));
- /* Get request lock first */
- if ((rv = apr_thread_mutex_lock(g_reqlock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't get request lock");
- return rv;
- }
+ /* Get request lock first */
+ if ((rv = apr_thread_mutex_lock(g_reqlock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't get request lock");
+ return rv;
+ }
- /* Try push the message */
- if ((rv = apr_queue_push(g_msgqueue, postcmd)) != APR_SUCCESS) {
- apr_thread_mutex_unlock(g_reqlock);
- free(postcmd);
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't push request message");
- return rv;
- } else {
- /* Wait the respond from process manager */
- char *notifybyte = NULL;
+ /* Try push the message */
+ if ((rv = apr_queue_push(g_msgqueue, postcmd)) != APR_SUCCESS) {
+ apr_thread_mutex_unlock(g_reqlock);
+ free(postcmd);
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't push request message");
+ return rv;
+ } else {
+ /* Wait the respond from process manager */
+ char *notifybyte = NULL;
- if ((rv =
- apr_queue_pop(g_notifyqueue,
- ¬ifybyte)) != APR_SUCCESS) {
- apr_thread_mutex_lock(g_reqlock);
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't pop notify message");
- return rv;
- }
- }
+ if ((rv =
+ apr_queue_pop(g_notifyqueue,
+ ¬ifybyte)) != APR_SUCCESS) {
+ apr_thread_mutex_lock(g_reqlock);
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't pop notify message");
+ return rv;
+ }
+ }
- /* Release the lock now */
- if (apr_thread_mutex_unlock(g_reqlock) != APR_SUCCESS) {
- /* It's a fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't release request lock");
- exit(1);
- }
- }
+ /* Release the lock now */
+ if (apr_thread_mutex_unlock(g_reqlock) != APR_SUCCESS) {
+ /* It's a fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't release request lock");
+ exit(1);
+ }
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t procmgr_finish_notify(server_rec * main_server)
{
- apr_status_t rv;
- char *notify = NULL;
+ apr_status_t rv;
+ char *notify = NULL;
- if ((rv = apr_queue_push(g_notifyqueue, notify)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't send spawn notify");
- }
+ if ((rv = apr_queue_push(g_notifyqueue, notify)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't send spawn notify");
+ }
- return rv;
+ return rv;
}
apr_status_t procmgr_peek_cmd(fcgid_command * command,
- server_rec * main_server)
+ server_rec * main_server)
{
- apr_status_t rv = APR_SUCCESS;
- fcgid_command *peakcmd = NULL;
+ apr_status_t rv = APR_SUCCESS;
+ fcgid_command *peakcmd = NULL;
- if (!g_must_exit && g_msgqueue) {
- if (apr_queue_pop(g_msgqueue, &peakcmd) == APR_SUCCESS) {
- if (!peakcmd)
- return APR_TIMEUP; /* This a wake up message */
- else {
- /* Copy the command, and then free the memory */
- memcpy(command, peakcmd, sizeof(*peakcmd));
- free(peakcmd);
+ if (!g_must_exit && g_msgqueue) {
+ if (apr_queue_pop(g_msgqueue, &peakcmd) == APR_SUCCESS) {
+ if (!peakcmd)
+ return APR_TIMEUP; /* This a wake up message */
+ else {
+ /* Copy the command, and then free the memory */
+ memcpy(command, peakcmd, sizeof(*peakcmd));
+ free(peakcmd);
- return APR_SUCCESS;
- }
- }
- }
+ return APR_SUCCESS;
+ }
+ }
+ }
- return APR_TIMEUP;
+ return APR_TIMEUP;
}
apr_status_t
procmgr_child_init(server_rec * main_server, apr_pool_t * pchild)
{
- apr_pool_cleanup_register(pchild, main_server,
- procmgr_stop_procmgr, apr_pool_cleanup_null);
- return APR_SUCCESS;
+ apr_pool_cleanup_register(pchild, main_server,
+ procmgr_stop_procmgr, apr_pool_cleanup_null);
+ return APR_SUCCESS;
}
int procmgr_must_exit()
{
- return g_must_exit;
+ return g_must_exit;
}
apr_status_t procmgr_stop_procmgr(void *server)
{
- apr_status_t status;
+ apr_status_t status;
- /* Tell the world to die */
- g_must_exit = 1;
- if (g_msgqueue)
- apr_queue_push(g_msgqueue, NULL);
+ /* Tell the world to die */
+ g_must_exit = 1;
+ if (g_msgqueue)
+ apr_queue_push(g_msgqueue, NULL);
- /* Wait */
- if (g_thread && apr_thread_join(&status, g_thread) == APR_SUCCESS) {
- /* Free the memory left in queue */
- fcgid_command *peakcmd = NULL;
+ /* Wait */
+ if (g_thread && apr_thread_join(&status, g_thread) == APR_SUCCESS) {
+ /* Free the memory left in queue */
+ fcgid_command *peakcmd = NULL;
- while (apr_queue_trypop(g_msgqueue, &peakcmd) == APR_SUCCESS) {
- if (peakcmd)
- free(peakcmd);
- }
- }
+ while (apr_queue_trypop(g_msgqueue, &peakcmd) == APR_SUCCESS) {
+ if (peakcmd)
+ free(peakcmd);
+ }
+ }
- if (g_wakeup_thread)
- return apr_thread_join(&status, g_wakeup_thread);
+ if (g_wakeup_thread)
+ return apr_thread_join(&status, g_wakeup_thread);
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
diff --git a/mod_fcgid/arch/win32/fcgid_proc_win.c b/mod_fcgid/arch/win32/fcgid_proc_win.c
index c3560de..fdb02d0 100644
--- a/mod_fcgid/arch/win32/fcgid_proc_win.c
+++ b/mod_fcgid/arch/win32/fcgid_proc_win.c
@@ -25,9 +25,9 @@
#endif
typedef struct {
- HANDLE handle_pipe;
- OVERLAPPED overlap_read;
- OVERLAPPED overlap_write;
+ HANDLE handle_pipe;
+ OVERLAPPED overlap_read;
+ OVERLAPPED overlap_write;
} fcgid_namedpipe_handle;
static int g_process_counter = 0;
@@ -35,528 +35,528 @@
static apr_status_t close_finish_event(void *finishevent)
{
- HANDLE *finish_event = finishevent;
+ HANDLE *finish_event = finishevent;
- CloseHandle(*finish_event);
- return APR_SUCCESS;
+ CloseHandle(*finish_event);
+ return APR_SUCCESS;
}
apr_status_t
proc_spawn_process(char *wrapperpath, fcgid_proc_info * procinfo,
- fcgid_procnode * procnode)
+ fcgid_procnode * procnode)
{
- HANDLE *finish_event, listen_handle;
- int bufused = 0;
- SECURITY_ATTRIBUTES SecurityAttributes;
- apr_procattr_t *proc_attr;
- apr_status_t rv;
- apr_file_t *file;
- char **proc_environ;
- char key_name[_POSIX_PATH_MAX];
- char sock_path[_POSIX_PATH_MAX];
- char *dummy;
- char *argv[2];
- int argc;
- char *wargv[APACHE_ARG_MAX], *word; /* For wrapper */
- const char *tmp;
+ HANDLE *finish_event, listen_handle;
+ int bufused = 0;
+ SECURITY_ATTRIBUTES SecurityAttributes;
+ apr_procattr_t *proc_attr;
+ apr_status_t rv;
+ apr_file_t *file;
+ char **proc_environ;
+ char key_name[_POSIX_PATH_MAX];
+ char sock_path[_POSIX_PATH_MAX];
+ char *dummy;
+ char *argv[2];
+ int argc;
+ char *wargv[APACHE_ARG_MAX], *word; /* For wrapper */
+ const char *tmp;
- /* Build wrapper args */
- argc = 0;
- tmp = wrapperpath;
- while (1) {
- word = ap_getword_white(procnode->proc_pool, &tmp);
- if (word == NULL || *word == '\0')
- break;
- if (argc >= APACHE_ARG_MAX)
- break;
- wargv[argc++] = word;
- }
- wargv[argc] = NULL;
+ /* Build wrapper args */
+ argc = 0;
+ tmp = wrapperpath;
+ while (1) {
+ word = ap_getword_white(procnode->proc_pool, &tmp);
+ if (word == NULL || *word == '\0')
+ break;
+ if (argc >= APACHE_ARG_MAX)
+ break;
+ wargv[argc++] = word;
+ }
+ wargv[argc] = NULL;
- memset(&SecurityAttributes, 0, sizeof(SecurityAttributes));
+ memset(&SecurityAttributes, 0, sizeof(SecurityAttributes));
- /* Create the pool if necessary */
- if (!g_inode_cginame_map)
- apr_pool_create(&g_inode_cginame_map,
- procinfo->main_server->process->pconf);
- if (!g_inode_cginame_map) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't cgi name map table");
- return APR_ENOMEM;
- }
+ /* Create the pool if necessary */
+ if (!g_inode_cginame_map)
+ apr_pool_create(&g_inode_cginame_map,
+ procinfo->main_server->process->pconf);
+ if (!g_inode_cginame_map) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't cgi name map table");
+ return APR_ENOMEM;
+ }
- /* Prepare finish event */
- finish_event = apr_palloc(procnode->proc_pool, sizeof(HANDLE));
- if (!finish_event) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't allocate finish event");
- return APR_ENOMEM;
- }
- *finish_event = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (*finish_event == NULL
- || !SetHandleInformation(*finish_event, HANDLE_FLAG_INHERIT, TRUE))
- {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't create mutex for subprocess");
- return APR_ENOLOCK;
- }
- apr_pool_cleanup_register(procnode->proc_pool, finish_event,
- close_finish_event, apr_pool_cleanup_null);
+ /* Prepare finish event */
+ finish_event = apr_palloc(procnode->proc_pool, sizeof(HANDLE));
+ if (!finish_event) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't allocate finish event");
+ return APR_ENOMEM;
+ }
+ *finish_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (*finish_event == NULL
+ || !SetHandleInformation(*finish_event, HANDLE_FLAG_INHERIT, TRUE))
+ {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't create mutex for subprocess");
+ return APR_ENOLOCK;
+ }
+ apr_pool_cleanup_register(procnode->proc_pool, finish_event,
+ close_finish_event, apr_pool_cleanup_null);
- /* For proc_kill_gracefully() */
- apr_pool_userdata_set(finish_event, FINISH_EVENT_DATA_NAME,
- NULL, procnode->proc_pool);
+ /* For proc_kill_gracefully() */
+ apr_pool_userdata_set(finish_event, FINISH_EVENT_DATA_NAME,
+ NULL, procnode->proc_pool);
- /* Pass the finish event id to subprocess */
- apr_table_setn(procinfo->proc_environ, SHUTDOWN_EVENT_NAME,
- apr_ltoa(procnode->proc_pool, (long) *finish_event));
+ /* Pass the finish event id to subprocess */
+ apr_table_setn(procinfo->proc_environ, SHUTDOWN_EVENT_NAME,
+ apr_ltoa(procnode->proc_pool, (long) *finish_event));
- /* Prepare the listen namedpipe file name */
- apr_snprintf(sock_path, _POSIX_PATH_MAX - 1,
- "\\\\.\\pipe\\fcgidpipe-%u.%lu",
- GetCurrentProcessId(), g_process_counter++);
+ /* Prepare the listen namedpipe file name */
+ apr_snprintf(sock_path, _POSIX_PATH_MAX - 1,
+ "\\\\.\\pipe\\fcgidpipe-%u.%lu",
+ GetCurrentProcessId(), g_process_counter++);
- /* Prepare the listen namedpipe handle */
- SecurityAttributes.bInheritHandle = TRUE;
- SecurityAttributes.nLength = sizeof(SecurityAttributes);
- SecurityAttributes.lpSecurityDescriptor = NULL;
- listen_handle = CreateNamedPipe(sock_path,
- PIPE_ACCESS_DUPLEX,
- PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |
- PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
- 8192, 8192, 0, &SecurityAttributes);
- if (listen_handle == INVALID_HANDLE_VALUE) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't create namedpipe for subprocess");
- return APR_ENOSOCKET;
- }
- strncpy(procnode->socket_path, sock_path, _POSIX_PATH_MAX - 1);
- procnode->socket_path[_POSIX_PATH_MAX - 1] = '\0';
+ /* Prepare the listen namedpipe handle */
+ SecurityAttributes.bInheritHandle = TRUE;
+ SecurityAttributes.nLength = sizeof(SecurityAttributes);
+ SecurityAttributes.lpSecurityDescriptor = NULL;
+ listen_handle = CreateNamedPipe(sock_path,
+ PIPE_ACCESS_DUPLEX,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |
+ PIPE_WAIT, PIPE_UNLIMITED_INSTANCES,
+ 8192, 8192, 0, &SecurityAttributes);
+ if (listen_handle == INVALID_HANDLE_VALUE) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't create namedpipe for subprocess");
+ return APR_ENOSOCKET;
+ }
+ strncpy(procnode->socket_path, sock_path, _POSIX_PATH_MAX - 1);
+ procnode->socket_path[_POSIX_PATH_MAX - 1] = '\0';
- /* Build environment variables */
- proc_environ = ap_create_environment(procnode->proc_pool,
- procinfo->proc_environ);
- if (!proc_environ) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- procinfo->main_server,
- "mod_fcgid: can't build environment variables");
- return APR_ENOMEM;
- }
+ /* Build environment variables */
+ proc_environ = ap_create_environment(procnode->proc_pool,
+ procinfo->proc_environ);
+ if (!proc_environ) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ procinfo->main_server,
+ "mod_fcgid: can't build environment variables");
+ return APR_ENOMEM;
+ }
- /* Create process now */
- if (!
- (procnode->proc_id =
- apr_pcalloc(procnode->proc_pool, sizeof(apr_proc_t)))
+ /* Create process now */
+ if (!
+ (procnode->proc_id =
+ apr_pcalloc(procnode->proc_pool, sizeof(apr_proc_t)))
|| (rv =
- apr_procattr_create(&proc_attr,
- procnode->proc_pool)) != APR_SUCCESS
+ apr_procattr_create(&proc_attr,
+ procnode->proc_pool)) != APR_SUCCESS
|| (rv =
- apr_procattr_dir_set(proc_attr,
- ap_make_dirstr_parent(procnode->proc_pool,
- (wrapperpath != NULL
- && wrapperpath[0] !=
- '\0') ? wargv[0] :
- procinfo->cgipath))) !=
+ apr_procattr_dir_set(proc_attr,
+ ap_make_dirstr_parent(procnode->proc_pool,
+ (wrapperpath != NULL
+ && wrapperpath[0] !=
+ '\0') ? wargv[0] :
+ procinfo->cgipath))) !=
APR_SUCCESS
|| (rv =
- apr_procattr_cmdtype_set(proc_attr, APR_PROGRAM)) != APR_SUCCESS
+ apr_procattr_cmdtype_set(proc_attr, APR_PROGRAM)) != APR_SUCCESS
|| (rv = apr_procattr_detach_set(proc_attr, 1)) != APR_SUCCESS
|| (rv =
- apr_os_file_put(&file, &listen_handle, 0,
- procnode->proc_pool)) != APR_SUCCESS
+ apr_os_file_put(&file, &listen_handle, 0,
+ procnode->proc_pool)) != APR_SUCCESS
|| (rv =
- apr_procattr_child_in_set(proc_attr, file, NULL)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, procinfo->main_server,
- "mod_fcgid: can't create fastcgi process attribute");
- CloseHandle(listen_handle);
- return APR_ENOPROC;
- }
+ apr_procattr_child_in_set(proc_attr, file, NULL)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, procinfo->main_server,
+ "mod_fcgid: can't create fastcgi process attribute");
+ CloseHandle(listen_handle);
+ return APR_ENOPROC;
+ }
- /* fork and exec now */
- if (wrapperpath != NULL && wrapperpath[0] != '\0') {
- ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, procinfo->main_server,
- "mod_fcgid: call %s with wrapper %s",
- procinfo->cgipath, wrapperpath);
- if ((rv =
- apr_proc_create(procnode->proc_id, wargv[0],
- (const char *const *) wargv,
- (const char *const *) proc_environ, proc_attr,
- procnode->proc_pool)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
- "mod_fcgid: can't create wrapper process for %s",
- procinfo->cgipath);
- CloseHandle(listen_handle);
- return rv;
- }
- } else {
- argv[0] = procinfo->cgipath;
- argv[1] = NULL;
- if ((rv =
- apr_proc_create(procnode->proc_id, procinfo->cgipath,
- (const char *const *) argv,
- (const char *const *) proc_environ, proc_attr,
- procnode->proc_pool)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
- "mod_fcgid: can't create process");
- CloseHandle(listen_handle);
- return rv;
- }
- }
+ /* fork and exec now */
+ if (wrapperpath != NULL && wrapperpath[0] != '\0') {
+ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, procinfo->main_server,
+ "mod_fcgid: call %s with wrapper %s",
+ procinfo->cgipath, wrapperpath);
+ if ((rv =
+ apr_proc_create(procnode->proc_id, wargv[0],
+ (const char *const *) wargv,
+ (const char *const *) proc_environ, proc_attr,
+ procnode->proc_pool)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
+ "mod_fcgid: can't create wrapper process for %s",
+ procinfo->cgipath);
+ CloseHandle(listen_handle);
+ return rv;
+ }
+ } else {
+ argv[0] = procinfo->cgipath;
+ argv[1] = NULL;
+ if ((rv =
+ apr_proc_create(procnode->proc_id, procinfo->cgipath,
+ (const char *const *) argv,
+ (const char *const *) proc_environ, proc_attr,
+ procnode->proc_pool)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, procinfo->main_server,
+ "mod_fcgid: can't create process");
+ CloseHandle(listen_handle);
+ return rv;
+ }
+ }
- /* OK, I created the process, now put it back to idle list */
- CloseHandle(listen_handle);
+ /* OK, I created the process, now put it back to idle list */
+ CloseHandle(listen_handle);
- /* Set the (deviceid, inode, shareid) -> fastcgi path map for log */
- apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX%lX",
- procnode->inode, procnode->deviceid,
- procnode->share_grp_id);
- dummy = NULL;
- apr_pool_userdata_get(&dummy, key_name, g_inode_cginame_map);
- if (!dummy) {
- /* Insert a new item if key not found */
- char *put_key = apr_psprintf(g_inode_cginame_map, "%lX%lX%lX",
- procnode->inode, procnode->deviceid,
- procnode->share_grp_id);
- char *fcgipath = apr_psprintf(g_inode_cginame_map, "%s",
- procinfo->cgipath);
+ /* Set the (deviceid, inode, shareid) -> fastcgi path map for log */
+ apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX%lX",
+ procnode->inode, procnode->deviceid,
+ procnode->share_grp_id);
+ dummy = NULL;
+ apr_pool_userdata_get(&dummy, key_name, g_inode_cginame_map);
+ if (!dummy) {
+ /* Insert a new item if key not found */
+ char *put_key = apr_psprintf(g_inode_cginame_map, "%lX%lX%lX",
+ procnode->inode, procnode->deviceid,
+ procnode->share_grp_id);
+ char *fcgipath = apr_psprintf(g_inode_cginame_map, "%s",
+ procinfo->cgipath);
- if (put_key && fcgipath)
- apr_pool_userdata_set(fcgipath, put_key, NULL,
- g_inode_cginame_map);
- }
+ if (put_key && fcgipath)
+ apr_pool_userdata_set(fcgipath, put_key, NULL,
+ g_inode_cginame_map);
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
proc_kill_gracefully(fcgid_procnode * procnode, server_rec * main_server)
{
- HANDLE *finish_event = NULL;
+ HANDLE *finish_event = NULL;
- apr_pool_userdata_get((void **) &finish_event,
- FINISH_EVENT_DATA_NAME, procnode->proc_pool);
+ apr_pool_userdata_get((void **) &finish_event,
+ FINISH_EVENT_DATA_NAME, procnode->proc_pool);
- if (finish_event != NULL)
- SetEvent(*finish_event);
- return APR_SUCCESS;
+ if (finish_event != NULL)
+ SetEvent(*finish_event);
+ return APR_SUCCESS;
}
apr_status_t proc_kill_force(fcgid_procnode * procnode,
- server_rec * main_server)
+ server_rec * main_server)
{
- return apr_proc_kill(procnode->proc_id, SIGKILL);
+ return apr_proc_kill(procnode->proc_id, SIGKILL);
}
apr_status_t
proc_wait_process(server_rec * main_server, fcgid_procnode * procnode)
{
- apr_status_t rv;
- int exitcode;
- apr_exit_why_e exitwhy;
+ apr_status_t rv;
+ int exitcode;
+ apr_exit_why_e exitwhy;
- if ((rv = apr_proc_wait(procnode->proc_id, &exitcode, &exitwhy,
- APR_NOWAIT)) == APR_CHILD_DONE) {
- /* Log why and how it die */
- proc_print_exit_info(procnode, exitcode, exitwhy, main_server);
+ if ((rv = apr_proc_wait(procnode->proc_id, &exitcode, &exitwhy,
+ APR_NOWAIT)) == APR_CHILD_DONE) {
+ /* Log why and how it die */
+ proc_print_exit_info(procnode, exitcode, exitwhy, main_server);
- /* Register the death */
- register_termination(main_server, procnode);
+ /* Register the death */
+ register_termination(main_server, procnode);
- /* Destroy pool */
- apr_pool_destroy(procnode->proc_pool);
- procnode->proc_pool = NULL;
- }
+ /* Destroy pool */
+ apr_pool_destroy(procnode->proc_pool);
+ procnode->proc_pool = NULL;
+ }
- return rv;
+ return rv;
}
static apr_status_t ipc_handle_cleanup(void *thehandle)
{
- fcgid_namedpipe_handle *handle = thehandle;
+ fcgid_namedpipe_handle *handle = thehandle;
- /* Sanity check */
- if (handle) {
- if (handle->handle_pipe != INVALID_HANDLE_VALUE)
- CloseHandle(handle->handle_pipe);
- if (handle->overlap_read.hEvent != NULL)
- CloseHandle(handle->overlap_read.hEvent);
- if (handle->overlap_write.hEvent != NULL)
- CloseHandle(handle->overlap_write.hEvent);
- handle->handle_pipe = INVALID_HANDLE_VALUE;
- handle->overlap_read.hEvent = NULL;
- handle->overlap_write.hEvent = NULL;
- }
+ /* Sanity check */
+ if (handle) {
+ if (handle->handle_pipe != INVALID_HANDLE_VALUE)
+ CloseHandle(handle->handle_pipe);
+ if (handle->overlap_read.hEvent != NULL)
+ CloseHandle(handle->overlap_read.hEvent);
+ if (handle->overlap_write.hEvent != NULL)
+ CloseHandle(handle->overlap_write.hEvent);
+ handle->handle_pipe = INVALID_HANDLE_VALUE;
+ handle->overlap_read.hEvent = NULL;
+ handle->overlap_write.hEvent = NULL;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
proc_connect_ipc(server_rec * main_server,
- fcgid_procnode * procnode, fcgid_ipc * ipc_handle)
+ fcgid_procnode * procnode, fcgid_ipc * ipc_handle)
{
- /* Prepare the ipc struct */
- fcgid_namedpipe_handle *handle_info;
+ /* Prepare the ipc struct */
+ fcgid_namedpipe_handle *handle_info;
- ipc_handle->ipc_handle_info =
- (fcgid_namedpipe_handle *) apr_pcalloc(ipc_handle->request->pool,
- sizeof
- (fcgid_namedpipe_handle));
- if (!ipc_handle->ipc_handle_info)
- return APR_ENOMEM;
+ ipc_handle->ipc_handle_info =
+ (fcgid_namedpipe_handle *) apr_pcalloc(ipc_handle->request->pool,
+ sizeof
+ (fcgid_namedpipe_handle));
+ if (!ipc_handle->ipc_handle_info)
+ return APR_ENOMEM;
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- /* Prepare OVERLAPPED struct for non-block I/O */
- handle_info->overlap_read.hEvent =
- CreateEvent(NULL, FALSE, FALSE, NULL);
- handle_info->overlap_write.hEvent =
- CreateEvent(NULL, FALSE, FALSE, NULL);
- handle_info->handle_pipe = INVALID_HANDLE_VALUE;
+ /* Prepare OVERLAPPED struct for non-block I/O */
+ handle_info->overlap_read.hEvent =
+ CreateEvent(NULL, FALSE, FALSE, NULL);
+ handle_info->overlap_write.hEvent =
+ CreateEvent(NULL, FALSE, FALSE, NULL);
+ handle_info->handle_pipe = INVALID_HANDLE_VALUE;
- apr_pool_cleanup_register(ipc_handle->request->pool,
- handle_info,
- ipc_handle_cleanup, apr_pool_cleanup_null);
+ apr_pool_cleanup_register(ipc_handle->request->pool,
+ handle_info,
+ ipc_handle_cleanup, apr_pool_cleanup_null);
- if (handle_info->overlap_read.hEvent == NULL
- || handle_info->overlap_write.hEvent == NULL)
- return APR_ENOMEM;
+ if (handle_info->overlap_read.hEvent == NULL
+ || handle_info->overlap_write.hEvent == NULL)
+ return APR_ENOMEM;
- /* Connect to name pipe */
- handle_info->handle_pipe = CreateFile(procnode->socket_path, GENERIC_READ | GENERIC_WRITE, 0, /* no sharing */
- NULL, /* no security attributes */
- OPEN_EXISTING, /* opens existing pipe */
- /*0 */ FILE_FLAG_OVERLAPPED,
- NULL /* no template file */ );
+ /* Connect to name pipe */
+ handle_info->handle_pipe = CreateFile(procnode->socket_path, GENERIC_READ | GENERIC_WRITE, 0, /* no sharing */
+ NULL, /* no security attributes */
+ OPEN_EXISTING, /* opens existing pipe */
+ /*0 */ FILE_FLAG_OVERLAPPED,
+ NULL /* no template file */ );
- if (handle_info->handle_pipe == INVALID_HANDLE_VALUE
- && ipc_handle->connect_timeout != 0
- && GetLastError() == ERROR_PIPE_BUSY) {
- /* Wait a while and try again */
- if (WaitNamedPipe
- (procnode->socket_path, ipc_handle->connect_timeout)) {
- handle_info->handle_pipe = CreateFile(procnode->socket_path, GENERIC_READ | GENERIC_WRITE, 0, /* no sharing */
- NULL, /* no security attributes */
- OPEN_EXISTING, /* opens existing pipe */
- 0, /* default attributes */
- NULL /* no template file */
- );
- }
- }
+ if (handle_info->handle_pipe == INVALID_HANDLE_VALUE
+ && ipc_handle->connect_timeout != 0
+ && GetLastError() == ERROR_PIPE_BUSY) {
+ /* Wait a while and try again */
+ if (WaitNamedPipe
+ (procnode->socket_path, ipc_handle->connect_timeout)) {
+ handle_info->handle_pipe = CreateFile(procnode->socket_path, GENERIC_READ | GENERIC_WRITE, 0, /* no sharing */
+ NULL, /* no security attributes */
+ OPEN_EXISTING, /* opens existing pipe */
+ 0, /* default attributes */
+ NULL /* no template file */
+ );
+ }
+ }
- if (handle_info->handle_pipe == INVALID_HANDLE_VALUE) {
- if (GetLastError() == ERROR_FILE_NOT_FOUND) /* The process has exited */
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
- "mod_fcgid: can't connect to named pipe, fastcgi server %d has been terminated",
- procnode->proc_id->pid);
- else
- ap_log_error(APLOG_MARK, APLOG_DEBUG, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't connect to named pipe, fastcgi server pid: %d",
- procnode->proc_id->pid);
- return APR_ESPIPE;
- }
+ if (handle_info->handle_pipe == INVALID_HANDLE_VALUE) {
+ if (GetLastError() == ERROR_FILE_NOT_FOUND) /* The process has exited */
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server,
+ "mod_fcgid: can't connect to named pipe, fastcgi server %d has been terminated",
+ procnode->proc_id->pid);
+ else
+ ap_log_error(APLOG_MARK, APLOG_DEBUG, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't connect to named pipe, fastcgi server pid: %d",
+ procnode->proc_id->pid);
+ return APR_ESPIPE;
+ }
- /* Now named pipe connected */
- return APR_SUCCESS;
+ /* Now named pipe connected */
+ return APR_SUCCESS;
}
apr_status_t proc_close_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle)
+ fcgid_ipc * ipc_handle)
{
- apr_status_t rv;
+ apr_status_t rv;
- rv = apr_pool_cleanup_run(ipc_handle->request->pool,
- ipc_handle->ipc_handle_info,
- ipc_handle_cleanup);
- ipc_handle->ipc_handle_info = NULL;
- return rv;
+ rv = apr_pool_cleanup_run(ipc_handle->request->pool,
+ ipc_handle->ipc_handle_info,
+ ipc_handle_cleanup);
+ ipc_handle->ipc_handle_info = NULL;
+ return rv;
}
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 rv;
- fcgid_namedpipe_handle *handle_info;
- DWORD bytesread;
+ apr_status_t rv;
+ fcgid_namedpipe_handle *handle_info;
+ DWORD bytesread;
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- if (ReadFile(handle_info->handle_pipe, (LPVOID) buffer,
- *size, &bytesread, &handle_info->overlap_read)) {
- *size = bytesread;
- return APR_SUCCESS;
- } else if ((rv = GetLastError()) != ERROR_IO_PENDING) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, APR_FROM_OS_ERROR(rv),
- main_server, "mod_fcgid: can't read from pipe");
- return rv;
- } else {
- /* it's ERROR_IO_PENDING */
- DWORD transferred;
- DWORD dwWaitResult
- = WaitForSingleObject(handle_info->overlap_read.hEvent,
- ipc_handle->communation_timeout * 1000);
+ if (ReadFile(handle_info->handle_pipe, (LPVOID) buffer,
+ *size, &bytesread, &handle_info->overlap_read)) {
+ *size = bytesread;
+ return APR_SUCCESS;
+ } else if ((rv = GetLastError()) != ERROR_IO_PENDING) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, APR_FROM_OS_ERROR(rv),
+ main_server, "mod_fcgid: can't read from pipe");
+ return rv;
+ } else {
+ /* it's ERROR_IO_PENDING */
+ DWORD transferred;
+ DWORD dwWaitResult
+ = WaitForSingleObject(handle_info->overlap_read.hEvent,
+ ipc_handle->communation_timeout * 1000);
- if (dwWaitResult == WAIT_OBJECT_0) {
- if (!GetOverlappedResult(handle_info->handle_pipe,
- &handle_info->overlap_read,
- &transferred, FALSE /* don't wait */ )
- || transferred == 0) {
- rv = apr_get_os_error();
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- rv, main_server,
- "mod_fcgid: get overlap result error");
- return rv;
- }
+ if (dwWaitResult == WAIT_OBJECT_0) {
+ if (!GetOverlappedResult(handle_info->handle_pipe,
+ &handle_info->overlap_read,
+ &transferred, FALSE /* don't wait */ )
+ || transferred == 0) {
+ rv = apr_get_os_error();
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ rv, main_server,
+ "mod_fcgid: get overlap result error");
+ return rv;
+ }
- *size = transferred;
- return APR_SUCCESS;
- } else {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
- main_server, "mod_fcgid: read timeout from pipe");
- return APR_ETIMEDOUT;
- }
- }
+ *size = transferred;
+ return APR_SUCCESS;
+ } else {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
+ main_server, "mod_fcgid: read timeout from pipe");
+ return APR_ETIMEDOUT;
+ }
+ }
}
apr_status_t proc_write_ipc(server_rec * main_server,
- fcgid_ipc * ipc_handle,
- apr_bucket_brigade * birgade_send)
+ fcgid_ipc * ipc_handle,
+ apr_bucket_brigade * birgade_send)
{
- fcgid_namedpipe_handle *handle_info;
- apr_bucket *bucket_request;
- apr_status_t rv;
- DWORD transferred;
+ fcgid_namedpipe_handle *handle_info;
+ apr_bucket *bucket_request;
+ apr_status_t rv;
+ DWORD transferred;
- handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
+ handle_info = (fcgid_namedpipe_handle *) ipc_handle->ipc_handle_info;
- for (bucket_request = APR_BRIGADE_FIRST(birgade_send);
- bucket_request != APR_BRIGADE_SENTINEL(birgade_send);
- bucket_request = APR_BUCKET_NEXT(bucket_request)) {
- char *write_buf;
- apr_size_t write_buf_len;
- apr_size_t has_write;
+ for (bucket_request = APR_BRIGADE_FIRST(birgade_send);
+ bucket_request != APR_BRIGADE_SENTINEL(birgade_send);
+ bucket_request = APR_BUCKET_NEXT(bucket_request)) {
+ char *write_buf;
+ apr_size_t write_buf_len;
+ apr_size_t has_write;
- if (APR_BUCKET_IS_EOS(bucket_request))
- break;
+ if (APR_BUCKET_IS_EOS(bucket_request))
+ break;
- if (APR_BUCKET_IS_FLUSH(bucket_request))
- continue;
+ if (APR_BUCKET_IS_FLUSH(bucket_request))
+ continue;
- if ((rv =
- apr_bucket_read(bucket_request, &write_buf, &write_buf_len,
- APR_BLOCK_READ)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
- "mod_fcgid: can't read request from bucket");
- return rv;
- }
+ if ((rv =
+ apr_bucket_read(bucket_request, &write_buf, &write_buf_len,
+ APR_BLOCK_READ)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, main_server,
+ "mod_fcgid: can't read request from bucket");
+ return rv;
+ }
- /* Write the buffer to fastcgi server */
- has_write = 0;
- while (has_write < write_buf_len) {
- DWORD byteswrite;
+ /* Write the buffer to fastcgi server */
+ has_write = 0;
+ while (has_write < write_buf_len) {
+ DWORD byteswrite;
- if (WriteFile(handle_info->handle_pipe,
- write_buf + has_write,
- write_buf_len - has_write,
- &byteswrite, &handle_info->overlap_write)) {
- has_write += byteswrite;
- continue;
- } else if ((rv = GetLastError()) != ERROR_IO_PENDING) {
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- APR_FROM_OS_ERROR(rv), main_server,
- "mod_fcgid: can't write to pipe");
- return rv;
- } else {
- /*
- it's ERROR_IO_PENDING on write
- */
- DWORD dwWaitResult
- =
- WaitForSingleObject(handle_info->overlap_write.hEvent,
- ipc_handle->communation_timeout *
- 1000);
- if (dwWaitResult == WAIT_OBJECT_0) {
- if (!GetOverlappedResult(handle_info->handle_pipe,
- &handle_info->overlap_write,
- &transferred,
- FALSE /* don't wait */ )
- || transferred == 0) {
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- apr_get_os_error(), main_server,
- "mod_fcgid: get overlap result error");
- return APR_ESPIPE;
- }
- has_write += transferred;
- continue;
- } else {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
- main_server,
- "mod_fcgid: write timeout to pipe");
- return APR_ESPIPE;
- }
- }
- }
- }
+ if (WriteFile(handle_info->handle_pipe,
+ write_buf + has_write,
+ write_buf_len - has_write,
+ &byteswrite, &handle_info->overlap_write)) {
+ has_write += byteswrite;
+ continue;
+ } else if ((rv = GetLastError()) != ERROR_IO_PENDING) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ APR_FROM_OS_ERROR(rv), main_server,
+ "mod_fcgid: can't write to pipe");
+ return rv;
+ } else {
+ /*
+ it's ERROR_IO_PENDING on write
+ */
+ DWORD dwWaitResult
+ =
+ WaitForSingleObject(handle_info->overlap_write.hEvent,
+ ipc_handle->communation_timeout *
+ 1000);
+ if (dwWaitResult == WAIT_OBJECT_0) {
+ if (!GetOverlappedResult(handle_info->handle_pipe,
+ &handle_info->overlap_write,
+ &transferred,
+ FALSE /* don't wait */ )
+ || transferred == 0) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ apr_get_os_error(), main_server,
+ "mod_fcgid: get overlap result error");
+ return APR_ESPIPE;
+ }
+ has_write += transferred;
+ continue;
+ } else {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
+ main_server,
+ "mod_fcgid: write timeout to pipe");
+ return APR_ESPIPE;
+ }
+ }
+ }
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
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)
{
- char *cgipath = NULL;
- char *diewhy = NULL;
- char key_name[_POSIX_PATH_MAX];
+ char *cgipath = NULL;
+ char *diewhy = NULL;
+ char key_name[_POSIX_PATH_MAX];
- /* Get the file name infomation base on inode and deviceid */
- apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX%lX",
- procnode->inode, procnode->deviceid,
- procnode->share_grp_id);
- apr_pool_userdata_get(&cgipath, key_name, g_inode_cginame_map);
+ /* Get the file name infomation base on inode and deviceid */
+ apr_snprintf(key_name, _POSIX_PATH_MAX, "%lX%lX%lX",
+ procnode->inode, procnode->deviceid,
+ procnode->share_grp_id);
+ apr_pool_userdata_get(&cgipath, key_name, g_inode_cginame_map);
- /* Reasons to exit */
- switch (procnode->diewhy) {
- case FCGID_DIE_KILLSELF:
- if (exitwhy == APR_PROC_EXIT)
- diewhy = "normal exit";
- else
- diewhy = "access violation";
- break;
- case FCGID_DIE_IDLE_TIMEOUT:
- diewhy = "idle timeout";
- break;
- case FCGID_DIE_LIFETIME_EXPIRED:
- diewhy = "lifetime expired";
- break;
- case FCGID_DIE_BUSY_TIMEOUT:
- diewhy = "busy timeout";
- break;
- case FCGID_DIE_CONNECT_ERROR:
- diewhy = "connect error, server may has exited";
- break;
- case FCGID_DIE_COMM_ERROR:
- diewhy = "communication error";
- break;
- case FCGID_DIE_SHUTDOWN:
- diewhy = "shutting down";
- break;
- default:
- diewhy = "unknow";
- }
+ /* Reasons to exit */
+ switch (procnode->diewhy) {
+ case FCGID_DIE_KILLSELF:
+ if (exitwhy == APR_PROC_EXIT)
+ diewhy = "normal exit";
+ else
+ diewhy = "access violation";
+ break;
+ case FCGID_DIE_IDLE_TIMEOUT:
+ diewhy = "idle timeout";
+ break;
+ case FCGID_DIE_LIFETIME_EXPIRED:
+ diewhy = "lifetime expired";
+ break;
+ case FCGID_DIE_BUSY_TIMEOUT:
+ diewhy = "busy timeout";
+ break;
+ case FCGID_DIE_CONNECT_ERROR:
+ diewhy = "connect error, server may has exited";
+ break;
+ case FCGID_DIE_COMM_ERROR:
+ diewhy = "communication error";
+ break;
+ case FCGID_DIE_SHUTDOWN:
+ diewhy = "shutting down";
+ break;
+ default:
+ diewhy = "unknow";
+ }
- /* Print log now */
- if (cgipath)
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
- "mod_fcgid: process %s(%d) exit(%s), return code %d",
- cgipath, procnode->proc_id->pid, diewhy, exitcode);
- else
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: can't get cgi name while exiting, exitcode: %d",
- exitcode);
+ /* Print log now */
+ if (cgipath)
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, main_server,
+ "mod_fcgid: process %s(%d) exit(%s), return code %d",
+ cgipath, procnode->proc_id->pid, diewhy, exitcode);
+ else
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: can't get cgi name while exiting, exitcode: %d",
+ exitcode);
}
diff --git a/mod_fcgid/arch/win32/fcgid_proctbl_win.c b/mod_fcgid/arch/win32/fcgid_proctbl_win.c
index 169617e..3562d88 100644
--- a/mod_fcgid/arch/win32/fcgid_proctbl_win.c
+++ b/mod_fcgid/arch/win32/fcgid_proctbl_win.c
@@ -5,173 +5,173 @@
static apr_thread_mutex_t *g_sharelock = NULL;
-static fcgid_procnode *g_proc_array = NULL; /* Contain all process slot */
-static fcgid_procnode *g_free_list_header = NULL; /* Attach to no process list */
-static fcgid_procnode *g_busy_list_header = NULL; /* Attach to a working process list */
-static fcgid_procnode *g_idle_list_header = NULL; /* Attach to an idle process list */
-static fcgid_procnode *g_error_list_header = NULL; /* Attach to an error process list */
+static fcgid_procnode *g_proc_array = NULL; /* Contain all process slot */
+static fcgid_procnode *g_free_list_header = NULL; /* Attach to no process list */
+static fcgid_procnode *g_busy_list_header = NULL; /* Attach to a working process list */
+static fcgid_procnode *g_idle_list_header = NULL; /* Attach to an idle process list */
+static fcgid_procnode *g_error_list_header = NULL; /* Attach to an error process list */
static fcgid_share *_global_memory = NULL;
-static fcgid_global_share *g_global_share = NULL; /* global information */
+static fcgid_global_share *g_global_share = NULL; /* global information */
static size_t g_table_size = FCGID_PROC_TABLE_SIZE;
apr_status_t
proctable_post_config(server_rec * main_server, apr_pool_t * pconf)
{
- long shmem_size = sizeof(fcgid_share);
- fcgid_procnode *ptmpnode = NULL;
- int i;
- apr_status_t rv = APR_SUCCESS;
+ long shmem_size = sizeof(fcgid_share);
+ fcgid_procnode *ptmpnode = NULL;
+ int i;
+ apr_status_t rv = APR_SUCCESS;
- if ((rv = apr_thread_mutex_create(&g_sharelock,
- APR_THREAD_MUTEX_DEFAULT,
- pconf)) != APR_SUCCESS) {
- /* Fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't create global mutex");
- exit(1);
- }
+ if ((rv = apr_thread_mutex_create(&g_sharelock,
+ APR_THREAD_MUTEX_DEFAULT,
+ pconf)) != APR_SUCCESS) {
+ /* Fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't create global mutex");
+ exit(1);
+ }
- /* There is only one process in WinNT mpm, share memory is not necessary */
- if ((_global_memory = ((fcgid_share *) apr_pcalloc(pconf,
- shmem_size))) ==
- NULL) {
- /* Fatal error */
- ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for size %ld",
- shmem_size);
- exit(1);
- }
+ /* There is only one process in WinNT mpm, share memory is not necessary */
+ if ((_global_memory = ((fcgid_share *) apr_pcalloc(pconf,
+ shmem_size))) ==
+ NULL) {
+ /* Fatal error */
+ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for size %ld",
+ shmem_size);
+ exit(1);
+ }
- g_proc_array = _global_memory->procnode_array;
- g_global_share = &_global_memory->global;
+ g_proc_array = _global_memory->procnode_array;
+ g_global_share = &_global_memory->global;
- g_global_share->must_exit = 0;
+ g_global_share->must_exit = 0;
- /* Init the array */
- g_idle_list_header = g_proc_array;
- g_busy_list_header = g_idle_list_header + 1;
- g_error_list_header = g_busy_list_header + 1;
- g_free_list_header = g_error_list_header + 1;
- ptmpnode = g_free_list_header;
- for (i = 0; i < FCGID_MAX_APPLICATION; i++) {
- ptmpnode->next_index = ptmpnode - g_proc_array + 1;
- ptmpnode++;
- }
+ /* Init the array */
+ g_idle_list_header = g_proc_array;
+ g_busy_list_header = g_idle_list_header + 1;
+ g_error_list_header = g_busy_list_header + 1;
+ g_free_list_header = g_error_list_header + 1;
+ ptmpnode = g_free_list_header;
+ for (i = 0; i < FCGID_MAX_APPLICATION; i++) {
+ ptmpnode->next_index = ptmpnode - g_proc_array + 1;
+ ptmpnode++;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t
proctable_child_init(server_rec * main_server, apr_pool_t * pchild)
{
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
apr_status_t proctable_lock_table()
{
- return apr_thread_mutex_lock(g_sharelock);
+ return apr_thread_mutex_lock(g_sharelock);
}
apr_status_t proctable_unlock_table()
{
- return apr_thread_mutex_unlock(g_sharelock);
+ return apr_thread_mutex_unlock(g_sharelock);
}
fcgid_procnode *proctable_get_free_list()
{
- return g_free_list_header;
+ return g_free_list_header;
}
fcgid_procnode *proctable_get_busy_list()
{
- return g_busy_list_header;
+ return g_busy_list_header;
}
fcgid_procnode *proctable_get_idle_list()
{
- return g_idle_list_header;
+ return g_idle_list_header;
}
fcgid_procnode *proctable_get_table_array()
{
- return g_proc_array;
+ return g_proc_array;
}
fcgid_procnode *proctable_get_error_list()
{
- return g_error_list_header;
+ return g_error_list_header;
}
fcgid_global_share *proctable_get_globalshare()
{
- return g_global_share;
+ return g_global_share;
}
size_t proctable_get_table_size()
{
- return g_table_size;
+ return g_table_size;
}
void safe_lock(server_rec * main_server)
{
- /* Lock error is a fatal error */
- apr_status_t rv;
+ /* Lock error is a fatal error */
+ apr_status_t rv;
- if ((rv = proctable_lock_table()) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't get lock");
- exit(1);
- }
+ if ((rv = proctable_lock_table()) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't get lock");
+ exit(1);
+ }
}
void safe_unlock(server_rec * main_server)
{
- /* Lock error is a fatal error */
- apr_status_t rv;
+ /* Lock error is a fatal error */
+ apr_status_t rv;
- if ((rv = proctable_unlock_table()) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: can't unlock");
- exit(1);
- }
+ if ((rv = proctable_unlock_table()) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: can't unlock");
+ exit(1);
+ }
}
void proctable_print_debug_info(server_rec * main_server)
{
- int freecount = 0;
- fcgid_procnode *current_node;
+ int freecount = 0;
+ fcgid_procnode *current_node;
- for (current_node = &g_proc_array[g_free_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index])
- freecount++;
+ for (current_node = &g_proc_array[g_free_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index])
+ freecount++;
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: total node count: %d, free node count: %d",
- FCGID_MAX_APPLICATION, freecount);
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: total node count: %d, free node count: %d",
+ FCGID_MAX_APPLICATION, freecount);
- for (current_node = &g_proc_array[g_idle_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: idle node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_idle_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: idle node index: %d",
+ current_node - g_proc_array);
+ }
- for (current_node = &g_proc_array[g_busy_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: busy node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_busy_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: busy node index: %d",
+ current_node - g_proc_array);
+ }
- for (current_node = &g_proc_array[g_error_list_header->next_index];
- current_node != g_proc_array;
- current_node = &g_proc_array[current_node->next_index]) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: error node index: %d",
- current_node - g_proc_array);
- }
+ for (current_node = &g_proc_array[g_error_list_header->next_index];
+ current_node != g_proc_array;
+ current_node = &g_proc_array[current_node->next_index]) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: error node index: %d",
+ current_node - g_proc_array);
+ }
}
diff --git a/mod_fcgid/fcgid_bridge.c b/mod_fcgid/fcgid_bridge.c
index 189bd4c..49eb443 100644
--- a/mod_fcgid/fcgid_bridge.c
+++ b/mod_fcgid/fcgid_bridge.c
@@ -40,650 +40,650 @@
static int g_max_requests_per_process;
static fcgid_procnode *apply_free_procnode(server_rec * main_server,
- fcgid_command * command)
+ fcgid_command * command)
{
- /* Scan idle list, find a node match inode, deviceid and groupid
- If there is no one there, return NULL */
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *busy_list_header, *proc_table;
- apr_ino_t inode = command->inode;
- apr_dev_t deviceid = command->deviceid;
- uid_t uid = command->uid;
- gid_t gid = command->gid;
- apr_size_t share_grp_id = command->share_grp_id;
- char *virtualhost = command->virtualhost;
+ /* Scan idle list, find a node match inode, deviceid and groupid
+ If there is no one there, return NULL */
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *busy_list_header, *proc_table;
+ apr_ino_t inode = command->inode;
+ apr_dev_t deviceid = command->deviceid;
+ uid_t uid = command->uid;
+ gid_t gid = command->gid;
+ apr_size_t share_grp_id = command->share_grp_id;
+ char *virtualhost = command->virtualhost;
- proc_table = proctable_get_table_array();
- previous_node = proctable_get_idle_list();
- busy_list_header = proctable_get_busy_list();
+ proc_table = proctable_get_table_array();
+ previous_node = proctable_get_idle_list();
+ busy_list_header = proctable_get_busy_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];
+ 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];
- if (current_node->inode == inode
- && current_node->deviceid == deviceid
- && current_node->share_grp_id == share_grp_id
- && current_node->virtualhost == virtualhost
- && current_node->uid == uid && current_node->gid == gid) {
- /* Unlink from idle list */
- previous_node->next_index = current_node->next_index;
+ if (current_node->inode == inode
+ && current_node->deviceid == deviceid
+ && current_node->share_grp_id == share_grp_id
+ && current_node->virtualhost == virtualhost
+ && current_node->uid == uid && current_node->gid == gid) {
+ /* Unlink from idle list */
+ previous_node->next_index = current_node->next_index;
- /* Link to busy list */
- current_node->next_index = busy_list_header->next_index;
- busy_list_header->next_index = current_node - proc_table;
+ /* Link to busy list */
+ current_node->next_index = busy_list_header->next_index;
+ busy_list_header->next_index = current_node - proc_table;
- safe_unlock(main_server);
- return current_node;
- } else
- previous_node = current_node;
+ safe_unlock(main_server);
+ return current_node;
+ } else
+ previous_node = current_node;
- current_node = next_node;
- }
- safe_unlock(main_server);
+ current_node = next_node;
+ }
+ safe_unlock(main_server);
- /* Found nothing */
- return NULL;
+ /* Found nothing */
+ return NULL;
}
static void
return_procnode(server_rec * main_server,
- fcgid_procnode * procnode, int communicate_error)
+ fcgid_procnode * procnode, int communicate_error)
{
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *proc_table = proctable_get_table_array();
- fcgid_procnode *error_list_header = proctable_get_error_list();
- fcgid_procnode *idle_list_header = proctable_get_idle_list();
- fcgid_procnode *busy_list_header = proctable_get_busy_list();
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *proc_table = proctable_get_table_array();
+ fcgid_procnode *error_list_header = proctable_get_error_list();
+ fcgid_procnode *idle_list_header = proctable_get_idle_list();
+ fcgid_procnode *busy_list_header = proctable_get_busy_list();
- safe_lock(main_server);
+ safe_lock(main_server);
- /* Unlink the node from busy list first */
- previous_node = busy_list_header;
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- next_node = &proc_table[current_node->next_index];
- if (current_node == procnode) {
- /* Unlink from busy list */
- previous_node->next_index = current_node->next_index;
- break;
- } else
- previous_node = current_node;
- current_node = next_node;
- }
+ /* Unlink the node from busy list first */
+ previous_node = busy_list_header;
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ next_node = &proc_table[current_node->next_index];
+ if (current_node == procnode) {
+ /* Unlink from busy list */
+ previous_node->next_index = current_node->next_index;
+ break;
+ } else
+ previous_node = current_node;
+ current_node = next_node;
+ }
- /* Return to error list or idle list */
- if (communicate_error) {
- /* Link to error list */
- procnode->next_index = error_list_header->next_index;
- error_list_header->next_index = procnode - proc_table;
- } else {
- /* Link to idle list */
- procnode->next_index = idle_list_header->next_index;
- idle_list_header->next_index = procnode - proc_table;
- }
+ /* Return to error list or idle list */
+ if (communicate_error) {
+ /* Link to error list */
+ procnode->next_index = error_list_header->next_index;
+ error_list_header->next_index = procnode - proc_table;
+ } else {
+ /* Link to idle list */
+ procnode->next_index = idle_list_header->next_index;
+ idle_list_header->next_index = procnode - proc_table;
+ }
- safe_unlock(main_server);
+ safe_unlock(main_server);
}
static int
count_busy_processes(server_rec * main_server, fcgid_command * command)
{
- int result = 0;
- fcgid_procnode *previous_node, *current_node, *next_node;
- fcgid_procnode *proc_table = proctable_get_table_array();
- fcgid_procnode *busy_list_header = proctable_get_busy_list();
+ int result = 0;
+ fcgid_procnode *previous_node, *current_node, *next_node;
+ fcgid_procnode *proc_table = proctable_get_table_array();
+ fcgid_procnode *busy_list_header = proctable_get_busy_list();
- safe_lock(main_server);
+ safe_lock(main_server);
- previous_node = busy_list_header;
- current_node = &proc_table[previous_node->next_index];
- while (current_node != proc_table) {
- 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) {
- result++;
- }
- next_node = &proc_table[current_node->next_index];
- current_node = next_node;
- }
+ previous_node = busy_list_header;
+ current_node = &proc_table[previous_node->next_index];
+ while (current_node != proc_table) {
+ 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) {
+ result++;
+ }
+ next_node = &proc_table[current_node->next_index];
+ current_node = next_node;
+ }
- safe_unlock(main_server);
+ safe_unlock(main_server);
- return result;
+ return result;
}
apr_status_t bucket_ctx_cleanup(void *thectx)
{
- /* Cleanup jobs:
- 1. Free bucket buffer
- 2. Return procnode
- NOTE: ipc will be clean when request pool cleanup, so I don't need to close it here
- */
- fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) thectx;
- server_rec *main_server = ctx->ipc.request->server;
+ /* Cleanup jobs:
+ 1. Free bucket buffer
+ 2. Return procnode
+ NOTE: ipc will be clean when request pool cleanup, so I don't need to close it here
+ */
+ fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) thectx;
+ server_rec *main_server = ctx->ipc.request->server;
- /* Free bucket buffer */
- if (ctx->buffer) {
- apr_bucket_destroy(ctx->buffer);
- ctx->buffer = NULL;
- }
+ /* Free bucket buffer */
+ if (ctx->buffer) {
+ apr_bucket_destroy(ctx->buffer);
+ ctx->buffer = NULL;
+ }
- proc_close_ipc(main_server, &ctx->ipc);
+ proc_close_ipc(main_server, &ctx->ipc);
- if (ctx->procnode) {
- /* Return procnode
- I will return this slot to idle(or error) list except:
- I take too much time on this request( greater than get_busy_timeout() ),
- so the process manager may have put this slot from busy list to error
- list, and the contain of this slot may have been modified
- In this case I will do nothing and return, let the process manager
- do the job
- */
- int dt =
- apr_time_sec(apr_time_now()) - apr_time_sec(ctx->active_time);
- if (dt > g_busy_timeout) {
- /* Do nothing but print log */
- ap_log_error(APLOG_MARK, APLOG_INFO, 0,
- main_server,
- "mod_fcgid: process busy timeout, take %d seconds for this request",
- dt);
- } else if (ctx->has_error) {
- ctx->procnode->diewhy = FCGID_DIE_COMM_ERROR;
- return_procnode(main_server, ctx->procnode,
- 1 /* communication error */ );
- } else if (g_max_requests_per_process != -1
- && ++ctx->procnode->requests_handled >=
- g_max_requests_per_process) {
- ctx->procnode->diewhy = FCGID_DIE_LIFETIME_EXPIRED;
- return_procnode(main_server, ctx->procnode,
- 1 /* handled all requests */ );
- } else
- return_procnode(main_server, ctx->procnode,
- 0 /* communication ok */ );
+ if (ctx->procnode) {
+ /* Return procnode
+ I will return this slot to idle(or error) list except:
+ I take too much time on this request( greater than get_busy_timeout() ),
+ so the process manager may have put this slot from busy list to error
+ list, and the contain of this slot may have been modified
+ In this case I will do nothing and return, let the process manager
+ do the job
+ */
+ int dt =
+ apr_time_sec(apr_time_now()) - apr_time_sec(ctx->active_time);
+ if (dt > g_busy_timeout) {
+ /* Do nothing but print log */
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0,
+ main_server,
+ "mod_fcgid: process busy timeout, take %d seconds for this request",
+ dt);
+ } else if (ctx->has_error) {
+ ctx->procnode->diewhy = FCGID_DIE_COMM_ERROR;
+ return_procnode(main_server, ctx->procnode,
+ 1 /* communication error */ );
+ } else if (g_max_requests_per_process != -1
+ && ++ctx->procnode->requests_handled >=
+ g_max_requests_per_process) {
+ ctx->procnode->diewhy = FCGID_DIE_LIFETIME_EXPIRED;
+ return_procnode(main_server, ctx->procnode,
+ 1 /* handled all requests */ );
+ } else
+ return_procnode(main_server, ctx->procnode,
+ 0 /* communication ok */ );
- ctx->procnode = NULL;
- }
+ ctx->procnode = NULL;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
static int getsfunc_fcgid_BRIGADE(char *buf, int len, void *arg)
{
- apr_bucket_brigade *bb = (apr_bucket_brigade *) arg;
- const char *dst_end = buf + len - 1; /* leave room for terminating null */
- char *dst = buf;
- apr_bucket *e = APR_BRIGADE_FIRST(bb);
- apr_status_t rv;
- int done = 0;
- int getLF = 0;
- int getColon = 0;
+ apr_bucket_brigade *bb = (apr_bucket_brigade *) arg;
+ const char *dst_end = buf + len - 1; /* leave room for terminating null */
+ char *dst = buf;
+ apr_bucket *e = APR_BRIGADE_FIRST(bb);
+ apr_status_t rv;
+ int done = 0;
+ int getLF = 0;
+ int getColon = 0;
- while ((dst < dst_end) && !done && !APR_BUCKET_IS_EOS(e)) {
- const char *bucket_data;
- apr_size_t bucket_data_len;
- const char *src;
- const char *src_end;
- apr_bucket *next;
+ while ((dst < dst_end) && !done && !APR_BUCKET_IS_EOS(e)) {
+ const char *bucket_data;
+ apr_size_t bucket_data_len;
+ const char *src;
+ const char *src_end;
+ apr_bucket *next;
- rv = apr_bucket_read(e, &bucket_data, &bucket_data_len,
- APR_BLOCK_READ);
- if (rv != APR_SUCCESS) {
- return 0;
- }
+ rv = apr_bucket_read(e, &bucket_data, &bucket_data_len,
+ APR_BLOCK_READ);
+ if (rv != APR_SUCCESS) {
+ return 0;
+ }
- /* Move on to next bucket if it's fastcgi header bucket */
- if (e->type == &ap_bucket_type_fcgid_header
- || e->type == &apr_bucket_type_immortal) {
- next = APR_BUCKET_NEXT(e);
- apr_bucket_delete(e);
- e = next;
- if (getLF) {
- done = 1;
- }
- continue;
- }
+ /* Move on to next bucket if it's fastcgi header bucket */
+ if (e->type == &ap_bucket_type_fcgid_header
+ || e->type == &apr_bucket_type_immortal) {
+ next = APR_BUCKET_NEXT(e);
+ apr_bucket_delete(e);
+ e = next;
+ if (getLF) {
+ done = 1;
+ }
+ continue;
+ }
- if (bucket_data_len == 0)
- return 0;
+ if (bucket_data_len == 0)
+ return 0;
- /* Base on RFC2616 section 4.2 */
- src = bucket_data;
- src_end = bucket_data + bucket_data_len;
- while ((src < src_end) && (dst < dst_end) && !done) {
- if (*src == ':')
- getColon = 1;
+ /* Base on RFC2616 section 4.2 */
+ src = bucket_data;
+ src_end = bucket_data + bucket_data_len;
+ while ((src < src_end) && (dst < dst_end) && !done) {
+ if (*src == ':')
+ getColon = 1;
- if (getLF && ((*src != ' ' && *src != '\t') || !getColon)) {
- done = 1;
- getColon = 0;
- break;
- } else if (getLF && (*src == ' ' || *src == '\t')) {
- *dst++ = '\r';
- *dst++ = '\n';
- getLF = 0;
- }
+ if (getLF && ((*src != ' ' && *src != '\t') || !getColon)) {
+ done = 1;
+ getColon = 0;
+ break;
+ } else if (getLF && (*src == ' ' || *src == '\t')) {
+ *dst++ = '\r';
+ *dst++ = '\n';
+ getLF = 0;
+ }
- if (*src == '\n') {
- getLF = 1;
- } else if (*src != '\r') {
- *dst++ = *src;
- }
- src++;
- }
+ if (*src == '\n') {
+ getLF = 1;
+ } else if (*src != '\r') {
+ *dst++ = *src;
+ }
+ src++;
+ }
- if (src < src_end) {
- apr_bucket_split(e, src - bucket_data);
- }
- next = APR_BUCKET_NEXT(e);
- apr_bucket_delete(e);
- e = next;
- }
- *dst = 0;
- return 1;
+ if (src < src_end) {
+ apr_bucket_split(e, src - bucket_data);
+ }
+ next = APR_BUCKET_NEXT(e);
+ apr_bucket_delete(e);
+ e = next;
+ }
+ *dst = 0;
+ return 1;
}
static int
handle_request(request_rec * r, int role, const char *argv0,
- fcgid_wrapper_conf * wrapper_conf,
- apr_bucket_brigade * output_brigade)
+ fcgid_wrapper_conf * wrapper_conf,
+ apr_bucket_brigade * output_brigade)
{
- apr_pool_t *request_pool = r->main ? r->main->pool : r->pool;
- server_rec *main_server = r->server;
- fcgid_command fcgi_request;
- fcgid_bucket_ctx *bucket_ctx;
- int i, j, cond_status;
- apr_status_t rv;
- apr_bucket_brigade *brigade_stdout;
- char sbuf[MAX_STRING_LEN];
- const char *location;
+ apr_pool_t *request_pool = r->main ? r->main->pool : r->pool;
+ server_rec *main_server = r->server;
+ fcgid_command fcgi_request;
+ fcgid_bucket_ctx *bucket_ctx;
+ int i, j, cond_status;
+ apr_status_t rv;
+ apr_bucket_brigade *brigade_stdout;
+ char sbuf[MAX_STRING_LEN];
+ const char *location;
- if (!g_variables_inited) {
- g_connect_timeout = get_ipc_connect_timeout(r->server);
- g_comm_timeout = get_ipc_comm_timeout(r->server);
- g_busy_timeout = get_busy_timeout(r->server);
- g_max_requests_per_process =
- get_max_requests_per_process(r->server);
- if (g_comm_timeout == 0)
- g_comm_timeout = 1;
- g_variables_inited = 1;
- }
+ if (!g_variables_inited) {
+ g_connect_timeout = get_ipc_connect_timeout(r->server);
+ g_comm_timeout = get_ipc_comm_timeout(r->server);
+ g_busy_timeout = get_busy_timeout(r->server);
+ g_max_requests_per_process =
+ get_max_requests_per_process(r->server);
+ if (g_comm_timeout == 0)
+ g_comm_timeout = 1;
+ g_variables_inited = 1;
+ }
- bucket_ctx = apr_pcalloc(request_pool, sizeof(*bucket_ctx));
- if (!bucket_ctx) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- r->server,
- "mod_fcgid: apr_calloc bucket_ctx failed in handle_request function");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- bucket_ctx->ipc.connect_timeout = g_connect_timeout;
- bucket_ctx->ipc.communation_timeout = g_comm_timeout;
- bucket_ctx->ipc.request = r;
- apr_pool_cleanup_register(request_pool, bucket_ctx,
- bucket_ctx_cleanup, apr_pool_cleanup_null);
+ bucket_ctx = apr_pcalloc(request_pool, sizeof(*bucket_ctx));
+ if (!bucket_ctx) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ r->server,
+ "mod_fcgid: apr_calloc bucket_ctx failed in handle_request function");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ bucket_ctx->ipc.connect_timeout = g_connect_timeout;
+ bucket_ctx->ipc.communation_timeout = g_comm_timeout;
+ bucket_ctx->ipc.request = r;
+ apr_pool_cleanup_register(request_pool, bucket_ctx,
+ bucket_ctx_cleanup, apr_pool_cleanup_null);
- /* Try to get a connected ipc handle */
- for (i = 0; i < FCGID_REQUEST_COUNT; i++) {
- /* Apply a free process slot, send a spawn request if I can't get one */
- for (j = 0; j < FCGID_APPLY_TRY_COUNT; j++) {
- apr_ino_t inode =
- wrapper_conf ? wrapper_conf->inode : r->finfo.inode;
- apr_dev_t deviceid =
- wrapper_conf ? wrapper_conf->deviceid : r->finfo.device;
- apr_size_t shareid =
- wrapper_conf ? wrapper_conf->share_group_id : 0;
+ /* Try to get a connected ipc handle */
+ for (i = 0; i < FCGID_REQUEST_COUNT; i++) {
+ /* Apply a free process slot, send a spawn request if I can't get one */
+ for (j = 0; j < FCGID_APPLY_TRY_COUNT; j++) {
+ apr_ino_t inode =
+ wrapper_conf ? wrapper_conf->inode : r->finfo.inode;
+ apr_dev_t deviceid =
+ wrapper_conf ? wrapper_conf->deviceid : r->finfo.device;
+ apr_size_t shareid =
+ wrapper_conf ? wrapper_conf->share_group_id : 0;
- /* Init spawn request */
- procmgr_init_spawn_cmd(&fcgi_request, r, argv0, deviceid,
- inode, shareid);
+ /* Init spawn request */
+ procmgr_init_spawn_cmd(&fcgi_request, r, argv0, deviceid,
+ inode, shareid);
- /* Apply a process slot */
- bucket_ctx->procnode =
- apply_free_procnode(r->server, &fcgi_request);
- if (bucket_ctx->procnode)
- break;
+ /* Apply a process slot */
+ bucket_ctx->procnode =
+ apply_free_procnode(r->server, &fcgi_request);
+ if (bucket_ctx->procnode)
+ break;
- /* Avoid sleeping the very first time through if there are no
- busy processes; the problem is just that we haven't spawned
- anything yet, so waiting is pointless */
- if (i > 0 || j > 0
- || count_busy_processes(r->server, &fcgi_request)) {
- apr_sleep(apr_time_from_sec(1));
+ /* Avoid sleeping the very first time through if there are no
+ busy processes; the problem is just that we haven't spawned
+ anything yet, so waiting is pointless */
+ if (i > 0 || j > 0
+ || count_busy_processes(r->server, &fcgi_request)) {
+ apr_sleep(apr_time_from_sec(1));
- bucket_ctx->procnode =
- apply_free_procnode(r->server, &fcgi_request);
- if (bucket_ctx->procnode)
- break;
- }
+ bucket_ctx->procnode =
+ apply_free_procnode(r->server, &fcgi_request);
+ if (bucket_ctx->procnode)
+ break;
+ }
- /* Send a spawn request if I can't get a process slot */
- procmgr_post_spawn_cmd(&fcgi_request, r);
- }
+ /* Send a spawn request if I can't get a process slot */
+ procmgr_post_spawn_cmd(&fcgi_request, r);
+ }
- /* Connect to the fastcgi server */
- if (bucket_ctx->procnode) {
- if (proc_connect_ipc
- (r->server, bucket_ctx->procnode,
- &bucket_ctx->ipc) != APR_SUCCESS) {
- proc_close_ipc(r->server, &bucket_ctx->ipc);
- bucket_ctx->procnode->diewhy = FCGID_DIE_CONNECT_ERROR;
- return_procnode(r->server, bucket_ctx->procnode,
- 1 /* has error */ );
- bucket_ctx->procnode = NULL;
- } else
- break;
- }
- }
+ /* Connect to the fastcgi server */
+ if (bucket_ctx->procnode) {
+ if (proc_connect_ipc
+ (r->server, bucket_ctx->procnode,
+ &bucket_ctx->ipc) != APR_SUCCESS) {
+ proc_close_ipc(r->server, &bucket_ctx->ipc);
+ bucket_ctx->procnode->diewhy = FCGID_DIE_CONNECT_ERROR;
+ return_procnode(r->server, bucket_ctx->procnode,
+ 1 /* has error */ );
+ bucket_ctx->procnode = NULL;
+ } else
+ break;
+ }
+ }
- /* Now I get a connected ipc handle */
- if (!bucket_ctx->procnode) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
- "mod_fcgid: can't apply process slot for %s", argv0);
- return HTTP_SERVICE_UNAVAILABLE;
- }
- bucket_ctx->active_time = bucket_ctx->procnode->last_active_time =
- apr_time_now();
+ /* Now I get a connected ipc handle */
+ if (!bucket_ctx->procnode) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server,
+ "mod_fcgid: can't apply process slot for %s", argv0);
+ return HTTP_SERVICE_UNAVAILABLE;
+ }
+ bucket_ctx->active_time = bucket_ctx->procnode->last_active_time =
+ apr_time_now();
- /* Write output_brigade to fastcgi server */
- if ((rv =
- proc_write_ipc(main_server, &bucket_ctx->ipc,
- output_brigade)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
- "mod_fcgid: write data to fastcgi server error");
- bucket_ctx->has_error = 1;
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* Write output_brigade to fastcgi server */
+ if ((rv =
+ proc_write_ipc(main_server, &bucket_ctx->ipc,
+ output_brigade)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
+ "mod_fcgid: write data to fastcgi server error");
+ bucket_ctx->has_error = 1;
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Create brigade */
- brigade_stdout =
- apr_brigade_create(request_pool, r->connection->bucket_alloc);
- if (!brigade_stdout) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
- "mod_fcgid: apr_brigade_create failed in handle_request function");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- APR_BRIGADE_INSERT_TAIL(brigade_stdout,
- ap_bucket_fcgid_header_create(r->connection->
- bucket_alloc,
- bucket_ctx));
- /*APR_BRIGADE_INSERT_TAIL(brigade_stdout, apr_bucket_flush_create(r->connection->bucket_alloc)); */
+ /* Create brigade */
+ brigade_stdout =
+ apr_brigade_create(request_pool, r->connection->bucket_alloc);
+ if (!brigade_stdout) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
+ "mod_fcgid: apr_brigade_create failed in handle_request function");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ APR_BRIGADE_INSERT_TAIL(brigade_stdout,
+ ap_bucket_fcgid_header_create(r->connection->
+ bucket_alloc,
+ bucket_ctx));
+ /*APR_BRIGADE_INSERT_TAIL(brigade_stdout, apr_bucket_flush_create(r->connection->bucket_alloc)); */
- /* Check the script header first. If got error, return immediately */
- if ((cond_status = ap_scan_script_header_err_core
- (r, sbuf, getsfunc_fcgid_BRIGADE, brigade_stdout)) >= 400)
- return cond_status;
+ /* Check the script header first. If got error, return immediately */
+ if ((cond_status = ap_scan_script_header_err_core
+ (r, sbuf, getsfunc_fcgid_BRIGADE, brigade_stdout)) >= 400)
+ return cond_status;
- /* Check redirect */
- location = apr_table_get(r->headers_out, "Location");
+ /* Check redirect */
+ location = apr_table_get(r->headers_out, "Location");
- if (location && location[0] == '/' && r->status == 200) {
- /* This redirect needs to be a GET no matter what the original
- * method was.
- */
- r->method = apr_pstrdup(r->pool, "GET");
- r->method_number = M_GET;
+ if (location && location[0] == '/' && r->status == 200) {
+ /* This redirect needs to be a GET no matter what the original
+ * method was.
+ */
+ r->method = apr_pstrdup(r->pool, "GET");
+ r->method_number = M_GET;
- /* We already read the message body (if any), so don't allow
- * the redirected request to think it has one. We can ignore
- * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
- */
- apr_table_unset(r->headers_in, "Content-Length");
+ /* We already read the message body (if any), so don't allow
+ * the redirected request to think it has one. We can ignore
+ * Transfer-Encoding, since we used REQUEST_CHUNKED_ERROR.
+ */
+ apr_table_unset(r->headers_in, "Content-Length");
- ap_internal_redirect_handler(location, r);
- return HTTP_OK;
- } else if (location && r->status == 200) {
- /* XX Note that if a script wants to produce its own Redirect
- * body, it now has to explicitly *say* "Status: 302"
- */
- return HTTP_MOVED_TEMPORARILY;
- }
+ ap_internal_redirect_handler(location, r);
+ return HTTP_OK;
+ } else if (location && r->status == 200) {
+ /* XX Note that if a script wants to produce its own Redirect
+ * body, it now has to explicitly *say* "Status: 302"
+ */
+ return HTTP_MOVED_TEMPORARILY;
+ }
- /* Now pass to output filter */
- if (role == FCGI_RESPONDER && (rv =
- ap_pass_brigade(r->output_filters,
- brigade_stdout)) !=
- APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
- "mod_fcgid: ap_pass_brigade failed in handle_request function");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* Now pass to output filter */
+ if (role == FCGI_RESPONDER && (rv =
+ ap_pass_brigade(r->output_filters,
+ brigade_stdout)) !=
+ APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
+ "mod_fcgid: ap_pass_brigade failed in handle_request function");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Retrun condition status */
- return cond_status;
+ /* Retrun condition status */
+ return cond_status;
}
int bridge_request(request_rec * r, int role, const char *argv0,
- fcgid_wrapper_conf * wrapper_conf)
+ fcgid_wrapper_conf * wrapper_conf)
{
- apr_pool_t *request_pool = r->main ? r->main->pool : r->pool;
- server_rec *main_server = r->server;
- apr_status_t rv = APR_SUCCESS;
- int seen_eos;
- size_t request_size = 0;
- apr_file_t *fd = NULL;
- int need_truncate = 1;
- apr_off_t cur_pos = 0;
- FCGI_Header *stdin_request_header;
- apr_bucket_brigade *output_brigade;
- apr_bucket *bucket_input, *bucket_header, *bucket_eos;
- size_t max_request_len = get_max_request_len(main_server);
- size_t max_mem_request_len = get_max_mem_request_len(main_server);
- char **envp = ap_create_environment(request_pool,
- r->subprocess_env);
+ apr_pool_t *request_pool = r->main ? r->main->pool : r->pool;
+ server_rec *main_server = r->server;
+ apr_status_t rv = APR_SUCCESS;
+ int seen_eos;
+ size_t request_size = 0;
+ apr_file_t *fd = NULL;
+ int need_truncate = 1;
+ apr_off_t cur_pos = 0;
+ FCGI_Header *stdin_request_header;
+ apr_bucket_brigade *output_brigade;
+ apr_bucket *bucket_input, *bucket_header, *bucket_eos;
+ size_t max_request_len = get_max_request_len(main_server);
+ size_t max_mem_request_len = get_max_mem_request_len(main_server);
+ char **envp = ap_create_environment(request_pool,
+ r->subprocess_env);
- /* Create brigade for the request to fastcgi server */
- output_brigade =
- apr_brigade_create(request_pool, r->connection->bucket_alloc);
- if (!output_brigade) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for output brigade");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* Create brigade for the request to fastcgi server */
+ output_brigade =
+ apr_brigade_create(request_pool, r->connection->bucket_alloc);
+ if (!output_brigade) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for output brigade");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Build the begin request and environ request, append them to output_brigade */
- if (!build_begin_block
- (role, r->server, r->connection->bucket_alloc, output_brigade)
- || !build_env_block(r->server, envp, r->connection->bucket_alloc,
- output_brigade)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
- main_server,
- "mod_fcgid: can't build begin or env request");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* Build the begin request and environ request, append them to output_brigade */
+ if (!build_begin_block
+ (role, r->server, r->connection->bucket_alloc, output_brigade)
+ || !build_env_block(r->server, envp, r->connection->bucket_alloc,
+ output_brigade)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0,
+ main_server,
+ "mod_fcgid: can't build begin or env request");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Stdin header and body */
- /* XXX HACK: I have to read all the request into memory before sending it
- to fastcgi application server, this prevents slow clients from
- keeping the server in processing too long.
- Buf sometimes it's not acceptable(think about uploading a larage attachment)
- file_bucket is a better choice in this case...
- To do, or not to do, that is the question ^_^
- */
- seen_eos = 0;
- do {
- apr_bucket_brigade *input_brigade =
- apr_brigade_create(request_pool,
- r->connection->bucket_alloc);
+ /* Stdin header and body */
+ /* XXX HACK: I have to read all the request into memory before sending it
+ to fastcgi application server, this prevents slow clients from
+ keeping the server in processing too long.
+ Buf sometimes it's not acceptable(think about uploading a larage attachment)
+ file_bucket is a better choice in this case...
+ To do, or not to do, that is the question ^_^
+ */
+ seen_eos = 0;
+ do {
+ apr_bucket_brigade *input_brigade =
+ apr_brigade_create(request_pool,
+ r->connection->bucket_alloc);
- if (!input_brigade
- || (rv = ap_get_brigade(r->input_filters, input_brigade,
- AP_MODE_READBYTES,
- APR_BLOCK_READ,
- HUGE_STRING_LEN)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv,
- main_server,
- "mod_fcgid: can't get data from http client");
- apr_brigade_destroy(output_brigade);
- if (input_brigade)
- apr_brigade_destroy(input_brigade);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ if (!input_brigade
+ || (rv = ap_get_brigade(r->input_filters, input_brigade,
+ AP_MODE_READBYTES,
+ APR_BLOCK_READ,
+ HUGE_STRING_LEN)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv,
+ main_server,
+ "mod_fcgid: can't get data from http client");
+ apr_brigade_destroy(output_brigade);
+ if (input_brigade)
+ apr_brigade_destroy(input_brigade);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- request_size = 0;
- for (bucket_input = APR_BRIGADE_FIRST(input_brigade);
- bucket_input != APR_BRIGADE_SENTINEL(input_brigade);
- bucket_input = APR_BUCKET_NEXT(bucket_input)) {
- const char *data;
- apr_size_t len;
- apr_bucket *bucket_stdin;
+ request_size = 0;
+ for (bucket_input = APR_BRIGADE_FIRST(input_brigade);
+ bucket_input != APR_BRIGADE_SENTINEL(input_brigade);
+ bucket_input = APR_BUCKET_NEXT(bucket_input)) {
+ const char *data;
+ apr_size_t len;
+ apr_bucket *bucket_stdin;
- if (APR_BUCKET_IS_EOS(bucket_input)) {
- seen_eos = 1;
- break;
- }
+ if (APR_BUCKET_IS_EOS(bucket_input)) {
+ seen_eos = 1;
+ break;
+ }
- if (APR_BUCKET_IS_METADATA(bucket_input))
- continue;
+ if (APR_BUCKET_IS_METADATA(bucket_input))
+ continue;
- if ((rv = apr_bucket_read(bucket_input, &data, &len,
- APR_BLOCK_READ)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv,
- main_server,
- "mod_fcgid: can't read request from HTTP client");
- apr_brigade_destroy(input_brigade);
- apr_brigade_destroy(output_brigade);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ if ((rv = apr_bucket_read(bucket_input, &data, &len,
+ APR_BLOCK_READ)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv,
+ main_server,
+ "mod_fcgid: can't read request from HTTP client");
+ apr_brigade_destroy(input_brigade);
+ apr_brigade_destroy(output_brigade);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Append a header, and the the bucket */
- stdin_request_header = apr_bucket_alloc(sizeof(FCGI_Header),
- r->connection->
- bucket_alloc);
- bucket_header =
- apr_bucket_heap_create((const char *) stdin_request_header,
- sizeof(*stdin_request_header),
- apr_bucket_free,
- r->connection->bucket_alloc);
+ /* Append a header, and the the bucket */
+ stdin_request_header = apr_bucket_alloc(sizeof(FCGI_Header),
+ r->connection->
+ bucket_alloc);
+ bucket_header =
+ apr_bucket_heap_create((const char *) stdin_request_header,
+ sizeof(*stdin_request_header),
+ apr_bucket_free,
+ r->connection->bucket_alloc);
- request_size += len;
- if (request_size > max_request_len) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: http request length %d > %d",
- request_size, max_request_len);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ request_size += len;
+ if (request_size > max_request_len) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: http request length %d > %d",
+ request_size, max_request_len);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- if (request_size > max_mem_request_len) {
- apr_size_t wrote_len;
- static const char *fd_key = "fcgid_fd";
+ if (request_size > max_mem_request_len) {
+ apr_size_t wrote_len;
+ static const char *fd_key = "fcgid_fd";
- if (fd == NULL)
- apr_pool_userdata_get((void **) &fd, fd_key,
- r->connection->pool);
+ if (fd == NULL)
+ apr_pool_userdata_get((void **) &fd, fd_key,
+ r->connection->pool);
- if (fd == NULL) {
- const char *tempdir = NULL;
- char *template;
+ if (fd == NULL) {
+ const char *tempdir = NULL;
+ char *template;
- rv = apr_temp_dir_get(&tempdir, r->pool);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- apr_get_os_error(), main_server,
- "mod_fcigd: can't get tmp dir");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ rv = apr_temp_dir_get(&tempdir, r->pool);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ apr_get_os_error(), main_server,
+ "mod_fcigd: can't get tmp dir");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- apr_filepath_merge(&template, tempdir,
- "fcgid.tmp.XXXXXX",
- APR_FILEPATH_NATIVE, r->pool);
- rv = apr_file_mktemp(&fd, template, 0,
- r->connection->pool);
- if (rv != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- apr_get_os_error(), main_server,
- "mod_fcgid: can't open tmp file fot stdin request");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- apr_pool_userdata_set((const void *) fd, fd_key,
- apr_pool_cleanup_null,
- r->connection->pool);
- } else if (need_truncate) {
- need_truncate = 0;
- apr_file_trunc(fd, 0);
- cur_pos = 0;
- }
- // Write request to tmp file
- if ((rv =
- apr_file_write_full(fd, (const void *) data, len,
- &wrote_len)) != APR_SUCCESS
- || len != wrote_len) {
- ap_log_error(APLOG_MARK, APLOG_WARNING,
- apr_get_os_error(), main_server,
- "mod_fcgid: can't write tmp file for stdin request");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- // Create file bucket
- bucket_stdin =
- apr_bucket_file_create(fd, cur_pos, len, r->pool,
- r->connection->bucket_alloc);
- cur_pos += len;
- } else {
- if (APR_BUCKET_IS_HEAP(bucket_input))
- apr_bucket_copy(bucket_input, &bucket_stdin);
- else {
- /* mod_ssl have a bug? */
- char *pcopydata =
- apr_bucket_alloc(len, r->connection->bucket_alloc);
- memcpy(pcopydata, data, len);
- bucket_stdin =
- apr_bucket_heap_create(pcopydata, len,
- apr_bucket_free,
- r->connection->
- bucket_alloc);
- }
- }
+ apr_filepath_merge(&template, tempdir,
+ "fcgid.tmp.XXXXXX",
+ APR_FILEPATH_NATIVE, r->pool);
+ rv = apr_file_mktemp(&fd, template, 0,
+ r->connection->pool);
+ if (rv != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ apr_get_os_error(), main_server,
+ "mod_fcgid: can't open tmp file fot stdin request");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ apr_pool_userdata_set((const void *) fd, fd_key,
+ apr_pool_cleanup_null,
+ r->connection->pool);
+ } else if (need_truncate) {
+ need_truncate = 0;
+ apr_file_trunc(fd, 0);
+ cur_pos = 0;
+ }
+ // Write request to tmp file
+ if ((rv =
+ apr_file_write_full(fd, (const void *) data, len,
+ &wrote_len)) != APR_SUCCESS
+ || len != wrote_len) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING,
+ apr_get_os_error(), main_server,
+ "mod_fcgid: can't write tmp file for stdin request");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ // Create file bucket
+ bucket_stdin =
+ apr_bucket_file_create(fd, cur_pos, len, r->pool,
+ r->connection->bucket_alloc);
+ cur_pos += len;
+ } else {
+ if (APR_BUCKET_IS_HEAP(bucket_input))
+ apr_bucket_copy(bucket_input, &bucket_stdin);
+ else {
+ /* mod_ssl have a bug? */
+ char *pcopydata =
+ apr_bucket_alloc(len, r->connection->bucket_alloc);
+ memcpy(pcopydata, data, len);
+ bucket_stdin =
+ apr_bucket_heap_create(pcopydata, len,
+ apr_bucket_free,
+ r->connection->
+ bucket_alloc);
+ }
+ }
- if (!stdin_request_header || !bucket_header || !bucket_stdin
- || !init_header(FCGI_STDIN, 1, len, 0,
- stdin_request_header)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for stdin request");
- apr_brigade_destroy(input_brigade);
- apr_brigade_destroy(output_brigade);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_header);
- APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_stdin);
- }
+ if (!stdin_request_header || !bucket_header || !bucket_stdin
+ || !init_header(FCGI_STDIN, 1, len, 0,
+ stdin_request_header)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for stdin request");
+ apr_brigade_destroy(input_brigade);
+ apr_brigade_destroy(output_brigade);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_header);
+ APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_stdin);
+ }
- apr_brigade_destroy(input_brigade);
- }
- while (!seen_eos);
+ apr_brigade_destroy(input_brigade);
+ }
+ while (!seen_eos);
- /* Append an empty body stdin header */
- stdin_request_header = apr_bucket_alloc(sizeof(FCGI_Header),
- r->connection->bucket_alloc);
- bucket_header =
- apr_bucket_heap_create((const char *) stdin_request_header,
- sizeof(*stdin_request_header),
- apr_bucket_free,
- r->connection->bucket_alloc);
- if (!stdin_request_header || !bucket_header
- || !init_header(FCGI_STDIN, 1, 0, 0, stdin_request_header)) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for stdin request");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_header);
+ /* Append an empty body stdin header */
+ stdin_request_header = apr_bucket_alloc(sizeof(FCGI_Header),
+ r->connection->bucket_alloc);
+ bucket_header =
+ apr_bucket_heap_create((const char *) stdin_request_header,
+ sizeof(*stdin_request_header),
+ apr_bucket_free,
+ r->connection->bucket_alloc);
+ if (!stdin_request_header || !bucket_header
+ || !init_header(FCGI_STDIN, 1, 0, 0, stdin_request_header)) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for stdin request");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_header);
- /* The eos bucket now */
- bucket_eos = apr_bucket_eos_create(r->connection->bucket_alloc);
- if (!bucket_eos) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
- main_server,
- "mod_fcgid: can't alloc memory for eos bucket");
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_eos);
+ /* The eos bucket now */
+ bucket_eos = apr_bucket_eos_create(r->connection->bucket_alloc);
+ if (!bucket_eos) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, apr_get_os_error(),
+ main_server,
+ "mod_fcgid: can't alloc memory for eos bucket");
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ APR_BRIGADE_INSERT_TAIL(output_brigade, bucket_eos);
- /* Bridge the request */
- return handle_request(r, role, argv0, wrapper_conf, output_brigade);
+ /* Bridge the request */
+ return handle_request(r, role, argv0, wrapper_conf, output_brigade);
}
diff --git a/mod_fcgid/fcgid_bridge.h b/mod_fcgid/fcgid_bridge.h
index 4d8a790..2e8c972 100644
--- a/mod_fcgid/fcgid_bridge.h
+++ b/mod_fcgid/fcgid_bridge.h
@@ -25,6 +25,6 @@
apr_status_t bucket_ctx_cleanup(void *thectx);
int bridge_request(request_rec * r, int role, const char *argv0,
- fcgid_wrapper_conf * wrapper_conf);
+ fcgid_wrapper_conf * wrapper_conf);
#endif
diff --git a/mod_fcgid/fcgid_bucket.c b/mod_fcgid/fcgid_bucket.c
index 84e1163..242a6bb 100644
--- a/mod_fcgid/fcgid_bucket.c
+++ b/mod_fcgid/fcgid_bucket.c
@@ -21,271 +21,271 @@
#define FCGID_FEED_LEN 8192
static apr_status_t fcgid_feed_data(fcgid_bucket_ctx * ctx,
- apr_bucket_alloc_t * bucketalloc,
- char **buffer, apr_size_t * bufferlen)
+ apr_bucket_alloc_t * bucketalloc,
+ char **buffer, apr_size_t * bufferlen)
{
- server_rec *main_server = ctx->ipc.request->server;
- apr_status_t rv;
+ server_rec *main_server = ctx->ipc.request->server;
+ apr_status_t rv;
- if (!ctx->buffer) {
- *buffer = apr_bucket_alloc(FCGID_FEED_LEN, bucketalloc);
- if (!buffer)
- return APR_ENOMEM;
+ if (!ctx->buffer) {
+ *buffer = apr_bucket_alloc(FCGID_FEED_LEN, bucketalloc);
+ if (!buffer)
+ return APR_ENOMEM;
- *bufferlen = FCGID_FEED_LEN;
- if ((rv =
- proc_read_ipc(main_server, &ctx->ipc, *buffer,
- bufferlen)) != APR_SUCCESS) {
- ctx->has_error = 1;
- apr_bucket_free(*buffer);
- return rv;
- }
+ *bufferlen = FCGID_FEED_LEN;
+ if ((rv =
+ proc_read_ipc(main_server, &ctx->ipc, *buffer,
+ bufferlen)) != APR_SUCCESS) {
+ ctx->has_error = 1;
+ apr_bucket_free(*buffer);
+ return rv;
+ }
- ctx->buffer =
- apr_bucket_heap_create(*buffer, FCGID_FEED_LEN,
- apr_bucket_free, bucketalloc);
- if (*bufferlen != FCGID_FEED_LEN) {
- apr_bucket *buckettmp;
+ ctx->buffer =
+ apr_bucket_heap_create(*buffer, FCGID_FEED_LEN,
+ apr_bucket_free, bucketalloc);
+ if (*bufferlen != FCGID_FEED_LEN) {
+ apr_bucket *buckettmp;
- apr_bucket_split(ctx->buffer, *bufferlen);
- buckettmp = APR_BUCKET_NEXT(ctx->buffer);
- apr_bucket_delete(buckettmp);
- }
- } else {
- apr_bucket_read(ctx->buffer, (const char **) buffer, bufferlen,
- APR_BLOCK_READ);
- }
- return APR_SUCCESS;
+ apr_bucket_split(ctx->buffer, *bufferlen);
+ buckettmp = APR_BUCKET_NEXT(ctx->buffer);
+ apr_bucket_delete(buckettmp);
+ }
+ } else {
+ apr_bucket_read(ctx->buffer, (const char **) buffer, bufferlen,
+ APR_BLOCK_READ);
+ }
+ return APR_SUCCESS;
}
static void fcgid_ignore_bytes(fcgid_bucket_ctx * ctx,
- apr_size_t ignorebyte)
+ apr_size_t ignorebyte)
{
- apr_bucket *buckettmp;
+ apr_bucket *buckettmp;
- if (ignorebyte == ctx->buffer->length) {
- apr_bucket_destroy(ctx->buffer);
- ctx->buffer = NULL;
- } else {
- apr_bucket_split(ctx->buffer, ignorebyte);
- buckettmp = ctx->buffer;
- ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
- apr_bucket_delete(buckettmp);
- }
+ if (ignorebyte == ctx->buffer->length) {
+ apr_bucket_destroy(ctx->buffer);
+ ctx->buffer = NULL;
+ } else {
+ apr_bucket_split(ctx->buffer, ignorebyte);
+ buckettmp = ctx->buffer;
+ ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
+ apr_bucket_delete(buckettmp);
+ }
}
static apr_status_t fcgid_header_bucket_read(apr_bucket * b,
- const char **str,
- apr_size_t * len,
- apr_read_type_e block)
+ const char **str,
+ apr_size_t * len,
+ apr_read_type_e block)
{
- fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) b->data;
- server_rec *main_server = ctx->ipc.request->server;
- apr_status_t rv;
- apr_size_t hasread, bodysize;
- FCGI_Header header;
- apr_bucket *curbucket = b;
+ fcgid_bucket_ctx *ctx = (fcgid_bucket_ctx *) b->data;
+ server_rec *main_server = ctx->ipc.request->server;
+ apr_status_t rv;
+ apr_size_t hasread, bodysize;
+ FCGI_Header header;
+ apr_bucket *curbucket = b;
- /* Keep reading until I get a fastcgi header */
- hasread = 0;
- while (hasread < sizeof(header)) {
- char *buffer;
- apr_size_t bufferlen, putsize;
+ /* Keep reading until I get a fastcgi header */
+ hasread = 0;
+ while (hasread < sizeof(header)) {
+ char *buffer;
+ apr_size_t bufferlen, putsize;
- /* Feed some data if necessary */
- if ((rv =
- fcgid_feed_data(ctx, b->list, &buffer,
- &bufferlen)) != APR_SUCCESS)
- return rv;
+ /* Feed some data if necessary */
+ if ((rv =
+ fcgid_feed_data(ctx, b->list, &buffer,
+ &bufferlen)) != APR_SUCCESS)
+ return rv;
- /* Initialize header */
- putsize = fcgid_min(bufferlen, sizeof(header) - hasread);
- memcpy(&header + hasread, buffer, putsize);
- hasread += putsize;
+ /* Initialize header */
+ putsize = fcgid_min(bufferlen, sizeof(header) - hasread);
+ memcpy(&header + hasread, buffer, putsize);
+ hasread += putsize;
- /* Ignore the bytes that have read */
- fcgid_ignore_bytes(ctx, putsize);
- }
+ /* Ignore the bytes that have read */
+ fcgid_ignore_bytes(ctx, putsize);
+ }
- /* Get the body size */
- bodysize = header.contentLengthB1;
- bodysize <<= 8;
- bodysize += header.contentLengthB0;
+ /* Get the body size */
+ bodysize = header.contentLengthB1;
+ bodysize <<= 8;
+ bodysize += header.contentLengthB0;
- /* Handle FCGI_STDERR body, write the content to log file */
- if (header.type == FCGI_STDERR) {
- char *logbuf = apr_bucket_alloc(APR_BUCKET_BUFF_SIZE, b->list);
- char *line;
+ /* Handle FCGI_STDERR body, write the content to log file */
+ if (header.type == FCGI_STDERR) {
+ char *logbuf = apr_bucket_alloc(APR_BUCKET_BUFF_SIZE, b->list);
+ char *line;
- if (!logbuf)
- return APR_ENOMEM;
- memset(logbuf, 0, APR_BUCKET_BUFF_SIZE);
+ if (!logbuf)
+ return APR_ENOMEM;
+ memset(logbuf, 0, APR_BUCKET_BUFF_SIZE);
- hasread = 0;
- while (hasread < bodysize) {
- char *buffer;
- apr_size_t bufferlen, canput, willput;
+ hasread = 0;
+ while (hasread < bodysize) {
+ char *buffer;
+ apr_size_t bufferlen, canput, willput;
- /* Feed some data if necessary */
- if ((rv =
- fcgid_feed_data(ctx, b->list, &buffer,
- &bufferlen)) != APR_SUCCESS) {
- apr_bucket_free(logbuf);
- return rv;
- }
+ /* Feed some data if necessary */
+ if ((rv =
+ fcgid_feed_data(ctx, b->list, &buffer,
+ &bufferlen)) != APR_SUCCESS) {
+ apr_bucket_free(logbuf);
+ return rv;
+ }
- canput = fcgid_min(bufferlen, bodysize - hasread);
- willput =
- fcgid_min(canput, APR_BUCKET_BUFF_SIZE - hasread - 1);
- memcpy(logbuf + hasread, buffer, willput);
- hasread += canput;
+ canput = fcgid_min(bufferlen, bodysize - hasread);
+ willput =
+ fcgid_min(canput, APR_BUCKET_BUFF_SIZE - hasread - 1);
+ memcpy(logbuf + hasread, buffer, willput);
+ hasread += canput;
- /* Ignore the "canput" bytes */
- fcgid_ignore_bytes(ctx, canput);
- }
+ /* Ignore the "canput" bytes */
+ fcgid_ignore_bytes(ctx, canput);
+ }
- /* Now I get the log data, write log and release the buffer */
- line = logbuf;
- while (*line) {
- char *end = strpbrk(line, "\r\n");
+ /* Now I get the log data, write log and release the buffer */
+ line = logbuf;
+ while (*line) {
+ char *end = strpbrk(line, "\r\n");
- if (end != NULL) {
- *end = '\0';
- }
- ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
- "mod_fcgid: stderr: %s", line);
- if (end == NULL) {
- break;
- }
- ++end;
- line = end + strspn(end, "\r\n");
- }
+ if (end != NULL) {
+ *end = '\0';
+ }
+ ap_log_error(APLOG_MARK, APLOG_WARNING, 0, main_server,
+ "mod_fcgid: stderr: %s", line);
+ if (end == NULL) {
+ break;
+ }
+ ++end;
+ line = end + strspn(end, "\r\n");
+ }
- apr_bucket_free(logbuf);
- }
+ apr_bucket_free(logbuf);
+ }
- /* if( header.type==FCGI_STDERR ) */
- /* Now handle FCGI_STDOUT */
- else if (header.type == FCGI_STDOUT) {
- hasread = 0;
- while (hasread < bodysize) {
- char *buffer;
- apr_size_t bufferlen, canput;
- apr_bucket *buckettmp;
+ /* if( header.type==FCGI_STDERR ) */
+ /* Now handle FCGI_STDOUT */
+ else if (header.type == FCGI_STDOUT) {
+ hasread = 0;
+ while (hasread < bodysize) {
+ char *buffer;
+ apr_size_t bufferlen, canput;
+ apr_bucket *buckettmp;
- /* Feed some data if necessary */
- if ((rv =
- fcgid_feed_data(ctx, b->list, &buffer,
- &bufferlen)) != APR_SUCCESS)
- return rv;
+ /* Feed some data if necessary */
+ if ((rv =
+ fcgid_feed_data(ctx, b->list, &buffer,
+ &bufferlen)) != APR_SUCCESS)
+ return rv;
- canput = fcgid_min(bufferlen, bodysize - hasread);
+ canput = fcgid_min(bufferlen, bodysize - hasread);
- /* Change the current bucket to refer to what we read */
- buckettmp = ctx->buffer;
- if (canput == (bodysize - hasread)) {
- apr_bucket_split(ctx->buffer, canput);
- ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
- APR_BUCKET_REMOVE(buckettmp);
- } else {
- /* canput==bufferlen */
- ctx->buffer = NULL;
- }
+ /* Change the current bucket to refer to what we read */
+ buckettmp = ctx->buffer;
+ if (canput == (bodysize - hasread)) {
+ apr_bucket_split(ctx->buffer, canput);
+ ctx->buffer = APR_BUCKET_NEXT(ctx->buffer);
+ APR_BUCKET_REMOVE(buckettmp);
+ } else {
+ /* canput==bufferlen */
+ ctx->buffer = NULL;
+ }
- APR_BUCKET_INSERT_AFTER(curbucket, buckettmp);
- curbucket = buckettmp;
- hasread += canput;
- } /* while( hasread<bodysize ) */
- }
+ APR_BUCKET_INSERT_AFTER(curbucket, buckettmp);
+ curbucket = buckettmp;
+ hasread += canput;
+ } /* while( hasread<bodysize ) */
+ }
- /* if( header.type==FCGI_STDOUT ) */
- /* Now FCGI_END_REQUEST */
- else if (header.type == FCGI_END_REQUEST) {
- /* Just ignore the body */
- hasread = 0;
- while (hasread < bodysize) {
- char *buffer;
- apr_size_t bufferlen, canignore;
+ /* if( header.type==FCGI_STDOUT ) */
+ /* Now FCGI_END_REQUEST */
+ else if (header.type == FCGI_END_REQUEST) {
+ /* Just ignore the body */
+ hasread = 0;
+ while (hasread < bodysize) {
+ char *buffer;
+ apr_size_t bufferlen, canignore;
- /* Feed some data if necessary */
- if ((rv =
- fcgid_feed_data(ctx, b->list, &buffer,
- &bufferlen)) != APR_SUCCESS)
- return rv;
+ /* Feed some data if necessary */
+ if ((rv =
+ fcgid_feed_data(ctx, b->list, &buffer,
+ &bufferlen)) != APR_SUCCESS)
+ return rv;
- canignore = fcgid_min(bufferlen, bodysize);
- hasread += canignore;
+ canignore = fcgid_min(bufferlen, bodysize);
+ hasread += canignore;
- /* Ignore the bytes */
- fcgid_ignore_bytes(ctx, canignore);
- }
- }
+ /* Ignore the bytes */
+ fcgid_ignore_bytes(ctx, canignore);
+ }
+ }
- /* Now ignore padding data */
- hasread = 0;
- while (hasread < header.paddingLength) {
- char *buffer;
- apr_size_t bufferlen, canignore;
+ /* Now ignore padding data */
+ hasread = 0;
+ while (hasread < header.paddingLength) {
+ char *buffer;
+ apr_size_t bufferlen, canignore;
- /* Feed some data if necessary */
- if ((rv =
- fcgid_feed_data(ctx, b->list, &buffer,
- &bufferlen)) != APR_SUCCESS)
- return rv;
+ /* Feed some data if necessary */
+ if ((rv =
+ fcgid_feed_data(ctx, b->list, &buffer,
+ &bufferlen)) != APR_SUCCESS)
+ return rv;
- canignore = fcgid_min(bufferlen, header.paddingLength - hasread);
- hasread += canignore;
+ canignore = fcgid_min(bufferlen, header.paddingLength - hasread);
+ hasread += canignore;
- /* Ignore the bytes */
- fcgid_ignore_bytes(ctx, canignore);
- }
+ /* Ignore the bytes */
+ fcgid_ignore_bytes(ctx, canignore);
+ }
- /* Tail another fastcgi header bucket if it's not ending */
- if (header.type != FCGI_END_REQUEST) {
- apr_bucket *headerbucket =
- ap_bucket_fcgid_header_create(b->list, ctx);
- if (!headerbucket)
- return APR_ENOMEM;
- APR_BUCKET_INSERT_AFTER(curbucket, headerbucket);
- } else {
- /* Release the process ASAP */
- if ((rv = apr_pool_cleanup_run(ctx->ipc.request->pool,
- ctx,
- bucket_ctx_cleanup)) != APR_SUCCESS)
- return rv;
- }
+ /* Tail another fastcgi header bucket if it's not ending */
+ if (header.type != FCGI_END_REQUEST) {
+ apr_bucket *headerbucket =
+ ap_bucket_fcgid_header_create(b->list, ctx);
+ if (!headerbucket)
+ return APR_ENOMEM;
+ APR_BUCKET_INSERT_AFTER(curbucket, headerbucket);
+ } else {
+ /* Release the process ASAP */
+ if ((rv = apr_pool_cleanup_run(ctx->ipc.request->pool,
+ ctx,
+ bucket_ctx_cleanup)) != APR_SUCCESS)
+ return rv;
+ }
- b = apr_bucket_immortal_make(b, "", 0);
- return apr_bucket_read(b, str, len, APR_BLOCK_READ);
+ b = apr_bucket_immortal_make(b, "", 0);
+ return apr_bucket_read(b, str, len, APR_BLOCK_READ);
}
apr_bucket *ap_bucket_fcgid_header_make(apr_bucket * b,
- fcgid_bucket_ctx * ctx)
+ fcgid_bucket_ctx * ctx)
{
- b->length = (apr_size_t) (-1);
- b->start = -1;
- b->data = ctx;
- b->type = &ap_bucket_type_fcgid_header;
+ b->length = (apr_size_t) (-1);
+ b->start = -1;
+ b->data = ctx;
+ b->type = &ap_bucket_type_fcgid_header;
- return b;
+ return b;
}
apr_bucket *ap_bucket_fcgid_header_create(apr_bucket_alloc_t * list,
- fcgid_bucket_ctx * ctx)
+ fcgid_bucket_ctx * ctx)
{
- apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
+ apr_bucket *b = apr_bucket_alloc(sizeof(*b), list);
- APR_BUCKET_INIT(b);
- b->free = apr_bucket_free;
- b->list = list;
- return ap_bucket_fcgid_header_make(b, ctx);
+ APR_BUCKET_INIT(b);
+ b->free = apr_bucket_free;
+ b->list = list;
+ return ap_bucket_fcgid_header_make(b, ctx);
}
const apr_bucket_type_t ap_bucket_type_fcgid_header = {
- "FCGID_HEADER", 5, APR_BUCKET_DATA,
- apr_bucket_destroy_noop,
- fcgid_header_bucket_read,
- apr_bucket_setaside_notimpl,
- apr_bucket_split_notimpl,
- apr_bucket_copy_notimpl
+ "FCGID_HEADER", 5, APR_BUCKET_DATA,
+ apr_bucket_destroy_noop,
+ fcgid_header_bucket_read,
+ apr_bucket_setaside_notimpl,
+ apr_bucket_split_notimpl,
+ apr_bucket_copy_notimpl
};
diff --git a/mod_fcgid/fcgid_bucket.h b/mod_fcgid/fcgid_bucket.h
index 0e138c5..56e6f73 100644
--- a/mod_fcgid/fcgid_bucket.h
+++ b/mod_fcgid/fcgid_bucket.h
@@ -21,16 +21,16 @@
#include "fcgid_proc.h"
typedef struct fcgid_bucket_ctx_t {
- fcgid_ipc ipc;
- apr_bucket *buffer;
- fcgid_procnode *procnode;
- apr_time_t active_time;
- int has_error;
+ fcgid_ipc ipc;
+ apr_bucket *buffer;
+ fcgid_procnode *procnode;
+ apr_time_t active_time;
+ int has_error;
} fcgid_bucket_ctx;
extern const apr_bucket_type_t ap_bucket_type_fcgid_header;
apr_bucket *ap_bucket_fcgid_header_create(apr_bucket_alloc_t * list,
- fcgid_bucket_ctx * ctx);
+ fcgid_bucket_ctx * ctx);
apr_bucket *ap_bucket_fcgid_header_make(apr_bucket *, fcgid_bucket_ctx *);
#endif
diff --git a/mod_fcgid/fcgid_conf.c b/mod_fcgid/fcgid_conf.c
index 59d8d62..7648fee 100644
--- a/mod_fcgid/fcgid_conf.c
+++ b/mod_fcgid/fcgid_conf.c
@@ -47,819 +47,819 @@
#define DEFAULT_IPC_COMM_TIMEOUT 40
#define DEFAULT_OUTPUT_BUFFERSIZE 65536
#define DEFAULT_MAX_REQUESTS_PER_PROCESS -1
-#define DEFAULT_MAX_REQUEST_LEN (1024*1024*1024) /* 1G */
-#define DEFAULT_MAX_MEM_REQUEST_LEN (1024*64) /* 64k */
+#define DEFAULT_MAX_REQUEST_LEN (1024*1024*1024) /* 1G */
+#define DEFAULT_MAX_MEM_REQUEST_LEN (1024*64) /* 64k */
static void init_server_config(apr_pool_t * p, fcgid_server_conf * config)
{
- config->default_init_env = NULL;
- config->pass_headers = NULL;
- config->sockname_prefix =
- ap_server_root_relative(p, DEFAULT_SOCKET_PREFIX);
- config->shmname_path = ap_server_root_relative(p, DEFAULT_SHM_PATH);
- config->idle_timeout = DEFAULT_IDLE_TIMEOUT;
- config->idle_scan_interval = DEFAULT_IDLE_SCAN_INTERVAL;
- config->busy_scan_interval = DEFAULT_BUSY_SCAN_INTERVAL;
- config->proc_lifetime = DEFAULT_PROC_LIFETIME;
- config->error_scan_interval = DEFAULT_ERROR_SCAN_INTERVAL;
- config->zombie_scan_interval = DEFAULT_ZOMBIE_SCAN_INTERVAL;
- config->spawn_score = DEFAULT_SPAWN_SCORE;
- config->spawnscore_uplimit = DEFAULT_SPAWNSOCRE_UPLIMIT;
- config->termination_score = DEFAULT_TERMINATION_SCORE;
- config->time_score = DEFAULT_TIME_SCORE;
- config->max_class_process_count = DEFAULT_MAX_CLASS_PROCESS_COUNT;
- config->min_class_process_count = DEFAULT_MIN_CLASS_PROCESS_COUNT;
- config->max_process_count = DEFAULT_MAX_PROCESS_COUNT;
- config->output_buffersize = DEFAULT_OUTPUT_BUFFERSIZE;
- config->ipc_comm_timeout = DEFAULT_IPC_COMM_TIMEOUT;
- config->ipc_connect_timeout = DEFAULT_IPC_CONNECT_TIMEOUT;
- config->busy_timeout = DEFAULT_BUSY_TIMEOUT;
- config->php_fix_pathinfo_enable = 0;
- config->max_requests_per_process = DEFAULT_MAX_REQUESTS_PER_PROCESS;
- config->max_request_len = DEFAULT_MAX_REQUEST_LEN;
- config->max_mem_request_len = DEFAULT_MAX_MEM_REQUEST_LEN;
+ config->default_init_env = NULL;
+ config->pass_headers = NULL;
+ config->sockname_prefix =
+ ap_server_root_relative(p, DEFAULT_SOCKET_PREFIX);
+ config->shmname_path = ap_server_root_relative(p, DEFAULT_SHM_PATH);
+ config->idle_timeout = DEFAULT_IDLE_TIMEOUT;
+ config->idle_scan_interval = DEFAULT_IDLE_SCAN_INTERVAL;
+ config->busy_scan_interval = DEFAULT_BUSY_SCAN_INTERVAL;
+ config->proc_lifetime = DEFAULT_PROC_LIFETIME;
+ config->error_scan_interval = DEFAULT_ERROR_SCAN_INTERVAL;
+ config->zombie_scan_interval = DEFAULT_ZOMBIE_SCAN_INTERVAL;
+ config->spawn_score = DEFAULT_SPAWN_SCORE;
+ config->spawnscore_uplimit = DEFAULT_SPAWNSOCRE_UPLIMIT;
+ config->termination_score = DEFAULT_TERMINATION_SCORE;
+ config->time_score = DEFAULT_TIME_SCORE;
+ config->max_class_process_count = DEFAULT_MAX_CLASS_PROCESS_COUNT;
+ config->min_class_process_count = DEFAULT_MIN_CLASS_PROCESS_COUNT;
+ config->max_process_count = DEFAULT_MAX_PROCESS_COUNT;
+ config->output_buffersize = DEFAULT_OUTPUT_BUFFERSIZE;
+ config->ipc_comm_timeout = DEFAULT_IPC_COMM_TIMEOUT;
+ config->ipc_connect_timeout = DEFAULT_IPC_CONNECT_TIMEOUT;
+ config->busy_timeout = DEFAULT_BUSY_TIMEOUT;
+ config->php_fix_pathinfo_enable = 0;
+ config->max_requests_per_process = DEFAULT_MAX_REQUESTS_PER_PROCESS;
+ config->max_request_len = DEFAULT_MAX_REQUEST_LEN;
+ config->max_mem_request_len = DEFAULT_MAX_MEM_REQUEST_LEN;
}
void *create_fcgid_server_config(apr_pool_t * p, server_rec * s)
{
- fcgid_server_conf *config = apr_pcalloc(p, sizeof(*config));
+ fcgid_server_conf *config = apr_pcalloc(p, sizeof(*config));
- init_server_config(p, config);
- return config;
+ init_server_config(p, config);
+ return config;
}
void *merge_fcgid_server_config(apr_pool_t * p, void *basev, void *locv)
{
- int i;
- fcgid_server_conf *merged_config =
- (fcgid_server_conf *) apr_pcalloc(p, sizeof(fcgid_server_conf));
- fcgid_server_conf *base = (fcgid_server_conf *) basev;
- fcgid_server_conf *local = (fcgid_server_conf *) locv;
- const apr_array_header_t *baseenv_array, *locenv_array;
+ int i;
+ fcgid_server_conf *merged_config =
+ (fcgid_server_conf *) apr_pcalloc(p, sizeof(fcgid_server_conf));
+ fcgid_server_conf *base = (fcgid_server_conf *) basev;
+ fcgid_server_conf *local = (fcgid_server_conf *) locv;
+ const apr_array_header_t *baseenv_array, *locenv_array;
- init_server_config(p, merged_config);
+ init_server_config(p, merged_config);
- /* Merge environment variables */
- baseenv_array = apr_table_elts(base->default_init_env);
- locenv_array = apr_table_elts(local->default_init_env);
+ /* Merge environment variables */
+ baseenv_array = apr_table_elts(base->default_init_env);
+ locenv_array = apr_table_elts(local->default_init_env);
- if (baseenv_array != NULL || locenv_array != NULL) {
- merged_config->default_init_env = apr_table_make(p, 20);
+ if (baseenv_array != NULL || locenv_array != NULL) {
+ merged_config->default_init_env = apr_table_make(p, 20);
- if (locenv_array != NULL) {
- const apr_table_entry_t *locenv_entry =
- (apr_table_entry_t *) locenv_array->elts;
+ if (locenv_array != NULL) {
+ const apr_table_entry_t *locenv_entry =
+ (apr_table_entry_t *) locenv_array->elts;
- for (i = 0; i < locenv_array->nelts; ++i) {
- apr_table_set(merged_config->default_init_env,
- locenv_entry[i].key, locenv_entry[i].val);
- }
- }
+ for (i = 0; i < locenv_array->nelts; ++i) {
+ apr_table_set(merged_config->default_init_env,
+ locenv_entry[i].key, locenv_entry[i].val);
+ }
+ }
- if (baseenv_array != NULL) {
- const apr_table_entry_t *baseenv_entry =
- (apr_table_entry_t *) baseenv_array->elts;
+ if (baseenv_array != NULL) {
+ const apr_table_entry_t *baseenv_entry =
+ (apr_table_entry_t *) baseenv_array->elts;
- for (i = 0; i < baseenv_array->nelts; ++i) {
- if (apr_table_get
- (merged_config->default_init_env,
- baseenv_entry[i].key))
- continue;
- apr_table_set(merged_config->default_init_env,
- baseenv_entry[i].key, baseenv_entry[i].val);
- }
- }
- }
+ for (i = 0; i < baseenv_array->nelts; ++i) {
+ if (apr_table_get
+ (merged_config->default_init_env,
+ baseenv_entry[i].key))
+ continue;
+ apr_table_set(merged_config->default_init_env,
+ baseenv_entry[i].key, baseenv_entry[i].val);
+ }
+ }
+ }
- /* Merge pass headers */
- if (local->pass_headers != NULL || base->pass_headers != NULL) {
- merged_config->pass_headers =
- apr_array_make(p, 10, sizeof(const char *));
- if (base->pass_headers != NULL)
- apr_array_cat(merged_config->pass_headers, base->pass_headers);
- if (local->pass_headers != NULL)
- apr_array_cat(merged_config->pass_headers,
- local->pass_headers);
- }
- // Merge the other configurations
- merged_config->ipc_comm_timeout = base->ipc_comm_timeout;
- merged_config->ipc_comm_timeout = local->ipc_comm_timeout;
+ /* Merge pass headers */
+ if (local->pass_headers != NULL || base->pass_headers != NULL) {
+ merged_config->pass_headers =
+ apr_array_make(p, 10, sizeof(const char *));
+ if (base->pass_headers != NULL)
+ apr_array_cat(merged_config->pass_headers, base->pass_headers);
+ if (local->pass_headers != NULL)
+ apr_array_cat(merged_config->pass_headers,
+ local->pass_headers);
+ }
+ // Merge the other configurations
+ merged_config->ipc_comm_timeout = base->ipc_comm_timeout;
+ merged_config->ipc_comm_timeout = local->ipc_comm_timeout;
- merged_config->ipc_connect_timeout = base->ipc_connect_timeout;
- merged_config->ipc_connect_timeout = local->ipc_connect_timeout;
+ merged_config->ipc_connect_timeout = base->ipc_connect_timeout;
+ merged_config->ipc_connect_timeout = local->ipc_connect_timeout;
- merged_config->busy_timeout = base->busy_timeout;
- merged_config->busy_timeout = local->busy_timeout;
+ merged_config->busy_timeout = base->busy_timeout;
+ merged_config->busy_timeout = local->busy_timeout;
- return merged_config;
+ return merged_config;
}
void *create_fcgid_dir_config(apr_pool_t * p, char *dummy)
{
- fcgid_dir_conf *config = apr_pcalloc(p, sizeof(fcgid_dir_conf));
+ fcgid_dir_conf *config = apr_pcalloc(p, sizeof(fcgid_dir_conf));
- config->wrapper_info_hash = apr_hash_make(p);
- config->authenticator_info = NULL;
- config->authenticator_authoritative = 1;
- config->authorizer_info = NULL;
- config->authorizer_authoritative = 1;
- config->access_info = NULL;
- config->access_authoritative = 1;
- return (void *) config;
+ config->wrapper_info_hash = apr_hash_make(p);
+ config->authenticator_info = NULL;
+ config->authenticator_authoritative = 1;
+ config->authorizer_info = NULL;
+ config->authorizer_authoritative = 1;
+ config->access_info = NULL;
+ config->access_authoritative = 1;
+ return (void *) config;
}
const char *set_idle_timeout(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->idle_timeout = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->idle_timeout = atol(arg);
+ return NULL;
}
int get_idle_timeout(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->idle_timeout : DEFAULT_IDLE_TIMEOUT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->idle_timeout : DEFAULT_IDLE_TIMEOUT;
}
const char *set_idle_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->idle_scan_interval = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->idle_scan_interval = atol(arg);
+ return NULL;
}
int get_idle_scan_interval(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->idle_scan_interval : DEFAULT_IDLE_TIMEOUT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->idle_scan_interval : DEFAULT_IDLE_TIMEOUT;
}
const char *set_busy_timeout(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->busy_timeout = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->busy_timeout = atol(arg);
+ return NULL;
}
int get_busy_timeout(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->busy_timeout : DEFAULT_BUSY_TIMEOUT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->busy_timeout : DEFAULT_BUSY_TIMEOUT;
}
const char *set_busy_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->busy_scan_interval = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->busy_scan_interval = atol(arg);
+ return NULL;
}
int get_busy_scan_interval(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- busy_scan_interval : DEFAULT_BUSY_SCAN_INTERVAL;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ busy_scan_interval : DEFAULT_BUSY_SCAN_INTERVAL;
}
const char *set_proc_lifetime(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->proc_lifetime = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->proc_lifetime = atol(arg);
+ return NULL;
}
int get_proc_lifetime(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->proc_lifetime : DEFAULT_PROC_LIFETIME;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->proc_lifetime : DEFAULT_PROC_LIFETIME;
}
const char *set_error_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->error_scan_interval = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->error_scan_interval = atol(arg);
+ return NULL;
}
int get_error_scan_interval(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- error_scan_interval : DEFAULT_ERROR_SCAN_INTERVAL;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ error_scan_interval : DEFAULT_ERROR_SCAN_INTERVAL;
}
const char *set_zombie_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->zombie_scan_interval = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->zombie_scan_interval = atol(arg);
+ return NULL;
}
int get_zombie_scan_interval(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- zombie_scan_interval : DEFAULT_ZOMBIE_SCAN_INTERVAL;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ zombie_scan_interval : DEFAULT_ZOMBIE_SCAN_INTERVAL;
}
const char *set_socketpath(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->sockname_prefix = ap_server_root_relative(cmd->pool, arg);
- if (!config->sockname_prefix)
- return "Invalid socket path";
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->sockname_prefix = ap_server_root_relative(cmd->pool, arg);
+ if (!config->sockname_prefix)
+ return "Invalid socket path";
- return NULL;
+ return NULL;
}
const char *get_socketpath(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config->sockname_prefix;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config->sockname_prefix;
}
const char *set_shmpath(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->shmname_path = ap_server_root_relative(cmd->pool, arg);
- if (!config->shmname_path)
- return "Invalid shmname path";
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->shmname_path = ap_server_root_relative(cmd->pool, arg);
+ if (!config->shmname_path)
+ return "Invalid shmname path";
- return NULL;
+ return NULL;
}
const char *get_shmpath(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config->shmname_path;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config->shmname_path;
}
const char *set_spawnscore_uplimit(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->spawnscore_uplimit = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->spawnscore_uplimit = atol(arg);
+ return NULL;
}
int get_spawnscore_uplimit(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- spawnscore_uplimit : DEFAULT_SPAWNSOCRE_UPLIMIT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ spawnscore_uplimit : DEFAULT_SPAWNSOCRE_UPLIMIT;
}
const char *set_max_request_len(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->max_request_len = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->max_request_len = atol(arg);
+ return NULL;
}
int get_max_request_len(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->max_request_len : DEFAULT_MAX_REQUEST_LEN;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->max_request_len : DEFAULT_MAX_REQUEST_LEN;
}
const char *set_max_mem_request_len(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->max_mem_request_len = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->max_mem_request_len = atol(arg);
+ return NULL;
}
int get_max_mem_request_len(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- max_mem_request_len : DEFAULT_MAX_MEM_REQUEST_LEN;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ max_mem_request_len : DEFAULT_MAX_MEM_REQUEST_LEN;
}
const char *set_spawn_score(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->spawn_score = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->spawn_score = atol(arg);
+ return NULL;
}
int get_spawn_score(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->spawn_score : DEFAULT_SPAWN_SCORE;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->spawn_score : DEFAULT_SPAWN_SCORE;
}
const char *set_time_score(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->time_score = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->time_score = atol(arg);
+ return NULL;
}
int get_time_score(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->time_score : DEFAULT_TIME_SCORE;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->time_score : DEFAULT_TIME_SCORE;
}
const char *set_termination_score(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->termination_score = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->termination_score = atol(arg);
+ return NULL;
}
int get_termination_score(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->termination_score : DEFAULT_TERMINATION_SCORE;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->termination_score : DEFAULT_TERMINATION_SCORE;
}
const char *set_max_process(cmd_parms * cmd, void *dummy, const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->max_process_count = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->max_process_count = atol(arg);
+ return NULL;
}
int get_max_process(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->max_process_count : DEFAULT_MAX_PROCESS_COUNT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->max_process_count : DEFAULT_MAX_PROCESS_COUNT;
}
const char *set_output_buffersize(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->output_buffersize = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->output_buffersize = atol(arg);
+ return NULL;
}
int get_output_buffersize(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->output_buffersize : DEFAULT_OUTPUT_BUFFERSIZE;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->output_buffersize : DEFAULT_OUTPUT_BUFFERSIZE;
}
const char *set_max_class_process(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->max_class_process_count = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->max_class_process_count = atol(arg);
+ return NULL;
}
int get_max_class_process(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- max_class_process_count : DEFAULT_MAX_CLASS_PROCESS_COUNT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ max_class_process_count : DEFAULT_MAX_CLASS_PROCESS_COUNT;
}
const char *set_min_class_process(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->min_class_process_count = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->min_class_process_count = atol(arg);
+ return NULL;
}
int get_min_class_process(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- min_class_process_count : DEFAULT_MIN_CLASS_PROCESS_COUNT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ min_class_process_count : DEFAULT_MIN_CLASS_PROCESS_COUNT;
}
const char *set_php_fix_pathinfo_enable(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->php_fix_pathinfo_enable = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->php_fix_pathinfo_enable = atol(arg);
+ return NULL;
}
const char *set_max_requests_per_process(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->max_requests_per_process = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->max_requests_per_process = atol(arg);
+ return NULL;
}
int get_max_requests_per_process(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- max_requests_per_process : DEFAULT_MAX_REQUESTS_PER_PROCESS;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ max_requests_per_process : DEFAULT_MAX_REQUESTS_PER_PROCESS;
}
int get_php_fix_pathinfo_enable(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->php_fix_pathinfo_enable : 0;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->php_fix_pathinfo_enable : 0;
}
const char *set_ipc_connect_timeout(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->ipc_connect_timeout = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->ipc_connect_timeout = atol(arg);
+ return NULL;
}
int get_ipc_connect_timeout(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->
- ipc_connect_timeout : DEFAULT_IPC_CONNECT_TIMEOUT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->
+ ipc_connect_timeout : DEFAULT_IPC_CONNECT_TIMEOUT;
}
const char *set_ipc_comm_timeout(cmd_parms * cmd, void *dummy,
- const char *arg)
+ const char *arg)
{
- server_rec *s = cmd->server;
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- config->ipc_comm_timeout = atol(arg);
- return NULL;
+ server_rec *s = cmd->server;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ config->ipc_comm_timeout = atol(arg);
+ return NULL;
}
int get_ipc_comm_timeout(server_rec * s)
{
- fcgid_server_conf *config =
- ap_get_module_config(s->module_config, &fcgid_module);
- return config ? config->ipc_comm_timeout : DEFAULT_IPC_COMM_TIMEOUT;
+ fcgid_server_conf *config =
+ ap_get_module_config(s->module_config, &fcgid_module);
+ return config ? config->ipc_comm_timeout : DEFAULT_IPC_COMM_TIMEOUT;
}
const char *add_default_env_vars(cmd_parms * cmd, void *dummy,
- const char *name, const char *value)
+ const char *name, const char *value)
{
- fcgid_server_conf *config =
- ap_get_module_config(cmd->server->module_config, &fcgid_module);;
- if (config->default_init_env == NULL)
- config->default_init_env = apr_table_make(cmd->pool, 20);
+ fcgid_server_conf *config =
+ ap_get_module_config(cmd->server->module_config, &fcgid_module);;
+ if (config->default_init_env == NULL)
+ config->default_init_env = apr_table_make(cmd->pool, 20);
- apr_table_set(config->default_init_env, name, value ? value : "");
- return NULL;
+ apr_table_set(config->default_init_env, name, value ? value : "");
+ return NULL;
}
apr_table_t *get_default_env_vars(request_rec * r)
{
- fcgid_server_conf *config =
- ap_get_module_config(r->server->module_config, &fcgid_module);
- return config->default_init_env;
+ fcgid_server_conf *config =
+ ap_get_module_config(r->server->module_config, &fcgid_module);
+ return config->default_init_env;
}
const char *add_pass_headers(cmd_parms * cmd, void *dummy,
- const char *names)
+ const char *names)
{
- const char **header;
- fcgid_server_conf *config =
- ap_get_module_config(cmd->server->module_config, &fcgid_module);
- if (config->pass_headers == NULL)
- config->pass_headers =
- apr_array_make(cmd->pool, 10, sizeof(const char *));
+ const char **header;
+ fcgid_server_conf *config =
+ ap_get_module_config(cmd->server->module_config, &fcgid_module);
+ if (config->pass_headers == NULL)
+ config->pass_headers =
+ apr_array_make(cmd->pool, 10, sizeof(const char *));
- header = (const char **) apr_array_push(config->pass_headers);
- *header = ap_getword_conf(cmd->pool, &names);
+ header = (const char **) apr_array_push(config->pass_headers);
+ *header = ap_getword_conf(cmd->pool, &names);
- return header ? NULL : "Invalid PassHeaders";
+ return header ? NULL : "Invalid PassHeaders";
}
apr_array_header_t *get_pass_headers(request_rec * r)
{
- fcgid_server_conf *config =
- ap_get_module_config(r->server->module_config, &fcgid_module);
- return config->pass_headers;
+ fcgid_server_conf *config =
+ ap_get_module_config(r->server->module_config, &fcgid_module);
+ return config->pass_headers;
}
const char *set_authenticator_info(cmd_parms * cmd, void *config,
- const char *authenticator)
+ const char *authenticator)
{
- apr_status_t rv;
- apr_finfo_t finfo;
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- /* Is the wrapper exist? */
- if ((rv = apr_stat(&finfo, authenticator, APR_FINFO_NORM,
- cmd->temp_pool)) != APR_SUCCESS) {
- return apr_psprintf(cmd->pool,
- "can't get authenticator file info: %s, errno: %d",
- authenticator, apr_get_os_error());
- }
+ /* Is the wrapper exist? */
+ if ((rv = apr_stat(&finfo, authenticator, APR_FINFO_NORM,
+ cmd->temp_pool)) != APR_SUCCESS) {
+ return apr_psprintf(cmd->pool,
+ "can't get authenticator file info: %s, errno: %d",
+ authenticator, apr_get_os_error());
+ }
- /* Create the wrapper node */
- dirconfig->authenticator_info =
- apr_pcalloc(cmd->server->process->pconf,
- sizeof(*dirconfig->authenticator_info));
- if (!dirconfig->authenticator_info)
- return "Can't alloc memory for authenticator_info";
- strncpy(dirconfig->authenticator_info->path, authenticator,
- _POSIX_PATH_MAX - 1);
- dirconfig->authenticator_info->path[_POSIX_PATH_MAX - 1] = '\0';
- dirconfig->authenticator_info->inode = finfo.inode;
- dirconfig->authenticator_info->deviceid = finfo.device;
- dirconfig->authenticator_info->share_group_id = (apr_size_t) - 1;
- return NULL;
+ /* Create the wrapper node */
+ dirconfig->authenticator_info =
+ apr_pcalloc(cmd->server->process->pconf,
+ sizeof(*dirconfig->authenticator_info));
+ if (!dirconfig->authenticator_info)
+ return "Can't alloc memory for authenticator_info";
+ strncpy(dirconfig->authenticator_info->path, authenticator,
+ _POSIX_PATH_MAX - 1);
+ dirconfig->authenticator_info->path[_POSIX_PATH_MAX - 1] = '\0';
+ dirconfig->authenticator_info->inode = finfo.inode;
+ dirconfig->authenticator_info->deviceid = finfo.device;
+ dirconfig->authenticator_info->share_group_id = (apr_size_t) - 1;
+ return NULL;
}
const char *set_authenticator_authoritative(cmd_parms * cmd,
- void *config, int arg)
+ void *config, int arg)
{
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- dirconfig->authenticator_authoritative = arg;
- return NULL;
+ dirconfig->authenticator_authoritative = arg;
+ return NULL;
}
auth_conf *get_authenticator_info(request_rec * r, int *authoritative)
{
- fcgid_dir_conf *config =
- ap_get_module_config(r->per_dir_config, &fcgid_module);
+ fcgid_dir_conf *config =
+ ap_get_module_config(r->per_dir_config, &fcgid_module);
- if (config != NULL && config->authenticator_info != NULL) {
- *authoritative = config->authenticator_authoritative;
- return config->authenticator_info;
- }
+ if (config != NULL && config->authenticator_info != NULL) {
+ *authoritative = config->authenticator_authoritative;
+ return config->authenticator_info;
+ }
- return NULL;
+ return NULL;
}
const char *set_authorizer_info(cmd_parms * cmd, void *config,
- const char *authorizer)
+ const char *authorizer)
{
- apr_status_t rv;
- apr_finfo_t finfo;
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- /* Is the wrapper exist? */
- if ((rv = apr_stat(&finfo, authorizer, APR_FINFO_NORM,
- cmd->temp_pool)) != APR_SUCCESS) {
- return apr_psprintf(cmd->pool,
- "can't get authorizer file info: %s, errno: %d",
- authorizer, apr_get_os_error());
- }
+ /* Is the wrapper exist? */
+ if ((rv = apr_stat(&finfo, authorizer, APR_FINFO_NORM,
+ cmd->temp_pool)) != APR_SUCCESS) {
+ return apr_psprintf(cmd->pool,
+ "can't get authorizer file info: %s, errno: %d",
+ authorizer, apr_get_os_error());
+ }
- /* Create the wrapper node */
- dirconfig->authorizer_info =
- apr_pcalloc(cmd->server->process->pconf,
- sizeof(*dirconfig->authorizer_info));
- if (!dirconfig->authorizer_info)
- return "Can't alloc memory for authorizer";
- strncpy(dirconfig->authorizer_info->path, authorizer,
- _POSIX_PATH_MAX - 1);
- dirconfig->authorizer_info->path[_POSIX_PATH_MAX - 1] = '\0';
- dirconfig->authorizer_info->inode = finfo.inode;
- dirconfig->authorizer_info->deviceid = finfo.device;
- dirconfig->authorizer_info->share_group_id = (apr_size_t) - 1;
- return NULL;
+ /* Create the wrapper node */
+ dirconfig->authorizer_info =
+ apr_pcalloc(cmd->server->process->pconf,
+ sizeof(*dirconfig->authorizer_info));
+ if (!dirconfig->authorizer_info)
+ return "Can't alloc memory for authorizer";
+ strncpy(dirconfig->authorizer_info->path, authorizer,
+ _POSIX_PATH_MAX - 1);
+ dirconfig->authorizer_info->path[_POSIX_PATH_MAX - 1] = '\0';
+ dirconfig->authorizer_info->inode = finfo.inode;
+ dirconfig->authorizer_info->deviceid = finfo.device;
+ dirconfig->authorizer_info->share_group_id = (apr_size_t) - 1;
+ return NULL;
}
const char *set_authorizer_authoritative(cmd_parms * cmd,
- void *config, int arg)
+ void *config, int arg)
{
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- dirconfig->authorizer_authoritative = arg;
- return NULL;
+ dirconfig->authorizer_authoritative = arg;
+ return NULL;
}
auth_conf *get_authorizer_info(request_rec * r, int *authoritative)
{
- fcgid_dir_conf *config =
- ap_get_module_config(r->per_dir_config, &fcgid_module);
+ fcgid_dir_conf *config =
+ ap_get_module_config(r->per_dir_config, &fcgid_module);
- if (config != NULL && config->authorizer_info != NULL) {
- *authoritative = config->authorizer_authoritative;
- return config->authorizer_info;
- }
+ if (config != NULL && config->authorizer_info != NULL) {
+ *authoritative = config->authorizer_authoritative;
+ return config->authorizer_info;
+ }
- return NULL;
+ return NULL;
}
const char *set_access_info(cmd_parms * cmd, void *config,
- const char *access)
+ const char *access)
{
- apr_status_t rv;
- apr_finfo_t finfo;
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- /* Is the wrapper exist? */
- if ((rv = apr_stat(&finfo, access, APR_FINFO_NORM,
- cmd->temp_pool)) != APR_SUCCESS) {
- return apr_psprintf(cmd->pool,
- "can't get authorizer file info: %s, errno: %d",
- access, apr_get_os_error());
- }
+ /* Is the wrapper exist? */
+ if ((rv = apr_stat(&finfo, access, APR_FINFO_NORM,
+ cmd->temp_pool)) != APR_SUCCESS) {
+ return apr_psprintf(cmd->pool,
+ "can't get authorizer file info: %s, errno: %d",
+ access, apr_get_os_error());
+ }
- /* Create the wrapper node */
- dirconfig->access_info =
- apr_pcalloc(cmd->server->process->pconf,
- sizeof(*dirconfig->access_info));
- if (!dirconfig->access_info)
- return "Can't alloc memory for access";
- strncpy(dirconfig->access_info->path, access, _POSIX_PATH_MAX - 1);
- dirconfig->access_info->path[_POSIX_PATH_MAX - 1] = '\0';
- dirconfig->access_info->inode = finfo.inode;
- dirconfig->access_info->deviceid = finfo.device;
- dirconfig->access_info->share_group_id = (apr_size_t) - 1;
- return NULL;
+ /* Create the wrapper node */
+ dirconfig->access_info =
+ apr_pcalloc(cmd->server->process->pconf,
+ sizeof(*dirconfig->access_info));
+ if (!dirconfig->access_info)
+ return "Can't alloc memory for access";
+ strncpy(dirconfig->access_info->path, access, _POSIX_PATH_MAX - 1);
+ dirconfig->access_info->path[_POSIX_PATH_MAX - 1] = '\0';
+ dirconfig->access_info->inode = finfo.inode;
+ dirconfig->access_info->deviceid = finfo.device;
+ dirconfig->access_info->share_group_id = (apr_size_t) - 1;
+ return NULL;
}
const char *set_access_authoritative(cmd_parms * cmd,
- void *config, int arg)
+ void *config, int arg)
{
- fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
+ fcgid_dir_conf *dirconfig = (fcgid_dir_conf *) config;
- dirconfig->access_authoritative = arg;
- return NULL;
+ dirconfig->access_authoritative = arg;
+ return NULL;
}
auth_conf *get_access_info(request_rec * r, int *authoritative)
{
- fcgid_dir_conf *config =
- ap_get_module_config(r->per_dir_config, &fcgid_module);
+ fcgid_dir_conf *config =
+ ap_get_module_config(r->per_dir_config, &fcgid_module);
- if (config != NULL && config->access_info != NULL) {
- *authoritative = config->access_authoritative;
- return config->access_info;
- }
+ if (config != NULL && config->access_info != NULL) {
+ *authoritative = config->access_authoritative;
+ return config->access_info;
+ }
- return NULL;
+ return NULL;
}
typedef struct {
- apr_hash_t *wrapper_id_hash;
- apr_size_t cur_id;
+ apr_hash_t *wrapper_id_hash;
+ apr_size_t cur_id;
} wrapper_id_info;
const char *set_wrapper_config(cmd_parms * cmd, void *dirconfig,
- const char *wrapperpath,
- const char *extension)
+ const char *wrapperpath,
+ const char *extension)
{
- const char *path, *tmp;
- apr_status_t rv;
- apr_finfo_t finfo;
- const char *userdata_key = "fcgid_wrapper_id";
- wrapper_id_info *id_info;
- apr_size_t *wrapper_id;
- fcgid_wrapper_conf *wrapper = NULL;
- fcgid_dir_conf *config = (fcgid_dir_conf *) dirconfig;
+ const char *path, *tmp;
+ apr_status_t rv;
+ apr_finfo_t finfo;
+ const char *userdata_key = "fcgid_wrapper_id";
+ wrapper_id_info *id_info;
+ apr_size_t *wrapper_id;
+ fcgid_wrapper_conf *wrapper = NULL;
+ fcgid_dir_conf *config = (fcgid_dir_conf *) dirconfig;
- /* Sanity check */
- if (wrapperpath == NULL || extension == NULL
- || *extension != '.' || *(extension + 1) == '\0'
- || strchr(extension, '/') || strchr(extension, '\\'))
- return "Invalid wrapper file extension";
+ /* Sanity check */
+ if (wrapperpath == NULL || extension == NULL
+ || *extension != '.' || *(extension + 1) == '\0'
+ || strchr(extension, '/') || strchr(extension, '\\'))
+ return "Invalid wrapper file extension";
- /* Get wrapper_id base on wrapperpath */
- apr_pool_userdata_get((void *) &id_info, userdata_key,
- cmd->server->process->pool);
- if (!id_info) {
- id_info =
- apr_pcalloc(cmd->server->process->pool, sizeof(*id_info));
- id_info->wrapper_id_hash =
- apr_hash_make(cmd->server->process->pool);
- apr_pool_userdata_set((const void *) id_info, userdata_key,
- apr_pool_cleanup_null,
- cmd->server->process->pool);
- }
- if ((wrapper_id =
- apr_hash_get(id_info->wrapper_id_hash, wrapperpath,
- strlen(wrapperpath))) == NULL) {
- wrapper_id =
- apr_pcalloc(cmd->server->process->pool, sizeof(*wrapper_id));
- *wrapper_id = id_info->cur_id++;
- apr_hash_set(id_info->wrapper_id_hash, wrapperpath,
- strlen(wrapperpath), wrapper_id);
- }
+ /* Get wrapper_id base on wrapperpath */
+ apr_pool_userdata_get((void *) &id_info, userdata_key,
+ cmd->server->process->pool);
+ if (!id_info) {
+ id_info =
+ apr_pcalloc(cmd->server->process->pool, sizeof(*id_info));
+ id_info->wrapper_id_hash =
+ apr_hash_make(cmd->server->process->pool);
+ apr_pool_userdata_set((const void *) id_info, userdata_key,
+ apr_pool_cleanup_null,
+ cmd->server->process->pool);
+ }
+ if ((wrapper_id =
+ apr_hash_get(id_info->wrapper_id_hash, wrapperpath,
+ strlen(wrapperpath))) == NULL) {
+ wrapper_id =
+ apr_pcalloc(cmd->server->process->pool, sizeof(*wrapper_id));
+ *wrapper_id = id_info->cur_id++;
+ apr_hash_set(id_info->wrapper_id_hash, wrapperpath,
+ strlen(wrapperpath), wrapper_id);
+ }
- wrapper = apr_pcalloc(cmd->server->process->pconf, sizeof(*wrapper));
- if (!wrapper)
- return "Can't alloc memory for wrapper";
+ wrapper = apr_pcalloc(cmd->server->process->pconf, sizeof(*wrapper));
+ if (!wrapper)
+ return "Can't alloc memory for wrapper";
- /* Get wrapper path */
- tmp = wrapperpath;
- path = ap_getword_white(cmd->temp_pool, &tmp);
- if (path == NULL || *path == '\0')
- return "Invalid wrapper config";
+ /* Get wrapper path */
+ tmp = wrapperpath;
+ path = ap_getword_white(cmd->temp_pool, &tmp);
+ if (path == NULL || *path == '\0')
+ return "Invalid wrapper config";
- /* Is the wrapper exist? */
- if ((rv = apr_stat(&finfo, path, APR_FINFO_NORM,
- cmd->temp_pool)) != APR_SUCCESS) {
- return apr_psprintf(cmd->pool,
- "can't get fastcgi file info: %s(%s), errno: %d",
- wrapperpath, path, apr_get_os_error());
- }
+ /* Is the wrapper exist? */
+ if ((rv = apr_stat(&finfo, path, APR_FINFO_NORM,
+ cmd->temp_pool)) != APR_SUCCESS) {
+ return apr_psprintf(cmd->pool,
+ "can't get fastcgi file info: %s(%s), errno: %d",
+ wrapperpath, path, apr_get_os_error());
+ }
- strncpy(wrapper->args, wrapperpath, _POSIX_PATH_MAX - 1);
- wrapper->args[_POSIX_PATH_MAX - 1] = '\0';
- wrapper->inode = finfo.inode;
- wrapper->deviceid = finfo.device;
- wrapper->share_group_id = *wrapper_id;
- *wrapper_id++;
+ strncpy(wrapper->args, wrapperpath, _POSIX_PATH_MAX - 1);
+ wrapper->args[_POSIX_PATH_MAX - 1] = '\0';
+ wrapper->inode = finfo.inode;
+ wrapper->deviceid = finfo.device;
+ wrapper->share_group_id = *wrapper_id;
+ *wrapper_id++;
- /* Add the node now */
- apr_hash_set(config->wrapper_info_hash, extension, strlen(extension),
- wrapper);
+ /* Add the node now */
+ apr_hash_set(config->wrapper_info_hash, extension, strlen(extension),
+ wrapper);
- return NULL;
+ return NULL;
}
fcgid_wrapper_conf *get_wrapper_info(const char *cgipath, request_rec * r)
{
- char *extension;
- fcgid_wrapper_conf *wrapper;
- fcgid_dir_conf *config =
- ap_get_module_config(r->per_dir_config, &fcgid_module);
+ char *extension;
+ fcgid_wrapper_conf *wrapper;
+ fcgid_dir_conf *config =
+ ap_get_module_config(r->per_dir_config, &fcgid_module);
- /* Get file name extension */
- extension = ap_strrchr_c(cgipath, '.');
- if (extension == NULL)
- return NULL;
+ /* Get file name extension */
+ extension = ap_strrchr_c(cgipath, '.');
+ if (extension == NULL)
+ return NULL;
- /* Search file name extension in per_dir_config */
- if (config
- && (wrapper =
- apr_hash_get(config->wrapper_info_hash, extension,
- strlen(extension))))
- return wrapper;
+ /* Search file name extension in per_dir_config */
+ if (config
+ && (wrapper =
+ apr_hash_get(config->wrapper_info_hash, extension,
+ strlen(extension))))
+ return wrapper;
- return NULL;
+ return NULL;
}
diff --git a/mod_fcgid/fcgid_conf.h b/mod_fcgid/fcgid_conf.h
index 1873cfc..3a62725 100644
--- a/mod_fcgid/fcgid_conf.h
+++ b/mod_fcgid/fcgid_conf.h
@@ -21,96 +21,96 @@
#include "fcgid_global.h"
typedef struct {
- char path[_POSIX_PATH_MAX];
- apr_ino_t inode;
- apr_dev_t deviceid;
- apr_size_t share_group_id;
+ char path[_POSIX_PATH_MAX];
+ apr_ino_t inode;
+ apr_dev_t deviceid;
+ apr_size_t share_group_id;
} auth_conf;
typedef struct {
- char args[_POSIX_PATH_MAX];
- apr_ino_t inode;
- apr_dev_t deviceid;
- apr_size_t share_group_id;
+ char args[_POSIX_PATH_MAX];
+ apr_ino_t inode;
+ apr_dev_t deviceid;
+ apr_size_t share_group_id;
} fcgid_wrapper_conf;
typedef struct {
- int idle_timeout;
- int idle_scan_interval;
- int busy_scan_interval;
- int proc_lifetime;
- int error_scan_interval;
- int zombie_scan_interval;
- char *sockname_prefix;
- char *shmname_path;
- int spawnscore_uplimit;
- int spawn_score;
- int termination_score;
- int time_score;
- int max_process_count;
- int max_class_process_count;
- int min_class_process_count;
- int max_request_len;
- int max_mem_request_len;
- int output_buffersize;
- int max_requests_per_process;
- apr_table_t *default_init_env;
- apr_array_header_t *pass_headers;
- int ipc_connect_timeout;
- int ipc_comm_timeout;
- int busy_timeout;
- int php_fix_pathinfo_enable;
+ int idle_timeout;
+ int idle_scan_interval;
+ int busy_scan_interval;
+ int proc_lifetime;
+ int error_scan_interval;
+ int zombie_scan_interval;
+ char *sockname_prefix;
+ char *shmname_path;
+ int spawnscore_uplimit;
+ int spawn_score;
+ int termination_score;
+ int time_score;
+ int max_process_count;
+ int max_class_process_count;
+ int min_class_process_count;
+ int max_request_len;
+ int max_mem_request_len;
+ int output_buffersize;
+ int max_requests_per_process;
+ apr_table_t *default_init_env;
+ apr_array_header_t *pass_headers;
+ int ipc_connect_timeout;
+ int ipc_comm_timeout;
+ int busy_timeout;
+ int php_fix_pathinfo_enable;
} fcgid_server_conf;
typedef struct {
- /* wrapper */
- apr_hash_t *wrapper_info_hash;
+ /* wrapper */
+ apr_hash_t *wrapper_info_hash;
- /* authenticator */
- auth_conf *authenticator_info;
- int authenticator_authoritative;
+ /* authenticator */
+ auth_conf *authenticator_info;
+ int authenticator_authoritative;
- /* authorizer */
- auth_conf *authorizer_info;
- int authorizer_authoritative;
+ /* authorizer */
+ auth_conf *authorizer_info;
+ int authorizer_authoritative;
- /* access check */
- auth_conf *access_info;
- int access_authoritative;
+ /* access check */
+ auth_conf *access_info;
+ int access_authoritative;
} fcgid_dir_conf;
void *create_fcgid_server_config(apr_pool_t * p, server_rec * s);
void *merge_fcgid_server_config(apr_pool_t * p, void *basev,
- void *overridesv);
+ void *overridesv);
void *create_fcgid_dir_config(apr_pool_t * p, char *dummy);
const char *set_idle_timeout(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_idle_timeout(server_rec * s);
const char *set_idle_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_idle_scan_interval(server_rec * s);
const char *set_busy_timeout(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_busy_timeout(server_rec * s);
const char *set_busy_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_busy_scan_interval(server_rec * s);
const char *set_proc_lifetime(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_proc_lifetime(server_rec * s);
const char *set_error_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_error_scan_interval(server_rec * s);
const char *set_zombie_scan_interval(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_zombie_scan_interval(server_rec * s);
const char *set_socketpath(cmd_parms * cmd, void *dummy, const char *arg);
@@ -123,84 +123,84 @@
int get_time_score(server_rec * s);
const char *set_max_request_len(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_max_request_len(server_rec * s);
const char *set_max_mem_request_len(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_max_mem_request_len(server_rec * s);
const char *set_termination_score(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_termination_score(server_rec * s);
const char *set_spawn_score(cmd_parms * cmd, void *dummy, const char *arg);
int get_spawn_score(server_rec * s);
const char *set_spawnscore_uplimit(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_spawnscore_uplimit(server_rec * s);
const char *set_max_process(cmd_parms * cmd, void *dummy, const char *arg);
int get_max_process(server_rec * s);
const char *set_max_class_process(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_max_class_process(server_rec * s);
const char *set_min_class_process(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_min_class_process(server_rec * s);
const char *set_ipc_connect_timeout(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_ipc_connect_timeout(server_rec * s);
const char *set_ipc_comm_timeout(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_ipc_comm_timeout(server_rec * s);
const char *set_output_buffersize(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_output_buffersize(server_rec * s);
const char *add_default_env_vars(cmd_parms * cmd, void *sconf,
- const char *name, const char *value);
+ const char *name, const char *value);
apr_table_t *get_default_env_vars(request_rec * r);
const char *add_pass_headers(cmd_parms * cmd, void *sconf,
- const char *name);
+ const char *name);
apr_array_header_t *get_pass_headers(request_rec * r);
const char *set_wrapper_config(cmd_parms * cmd, void *dummy,
- const char *wrapper, const char *extension);
+ const char *wrapper, const char *extension);
fcgid_wrapper_conf *get_wrapper_info(const char *cgipath, request_rec * r);
const char *set_authenticator_info(cmd_parms * cmd, void *config,
- const char *arg);
+ const char *arg);
const char *set_authenticator_authoritative(cmd_parms * cmd,
- void *config, int arg);
+ void *config, int arg);
auth_conf *get_authenticator_info(request_rec * r, int *authoritative);
const char *set_authorizer_info(cmd_parms * cmd, void *config,
- const char *arg);
+ const char *arg);
const char *set_authorizer_authoritative(cmd_parms * cmd,
- void *config, int arg);
+ void *config, int arg);
auth_conf *get_authorizer_info(request_rec * r, int *authoritative);
const char *set_access_info(cmd_parms * cmd, void *config,
- const char *arg);
+ const char *arg);
const char *set_access_authoritative(cmd_parms * cmd,
- void *config, int arg);
+ void *config, int arg);
auth_conf *get_access_info(request_rec * r, int *authoritative);
const char *set_php_fix_pathinfo_enable(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_php_fix_pathinfo_enable(server_rec * s);
const char *set_max_requests_per_process(cmd_parms * cmd, void *dummy,
- const char *arg);
+ const char *arg);
int get_max_requests_per_process(server_rec * s);
#endif
diff --git a/mod_fcgid/fcgid_filter.c b/mod_fcgid/fcgid_filter.c
index e6ed1cf..669cebb 100644
--- a/mod_fcgid/fcgid_filter.c
+++ b/mod_fcgid/fcgid_filter.c
@@ -26,80 +26,80 @@
apr_status_t fcgid_filter(ap_filter_t * f, apr_bucket_brigade * bb)
{
- apr_status_t rv;
- apr_bucket_brigade *tmp_brigade;
- int save_size = 0;
- conn_rec *c = f->c;
- server_rec *main_server = f->r->server;
+ apr_status_t rv;
+ apr_bucket_brigade *tmp_brigade;
+ int save_size = 0;
+ conn_rec *c = f->c;
+ server_rec *main_server = f->r->server;
- if (!g_hasinit) {
- g_buffsize = get_output_buffersize(main_server);
- g_hasinit = 1;
- }
+ if (!g_hasinit) {
+ g_buffsize = get_output_buffersize(main_server);
+ g_hasinit = 1;
+ }
- tmp_brigade =
- apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc);
- while (!APR_BRIGADE_EMPTY(bb)) {
- apr_size_t readlen;
- const char *buffer;
+ tmp_brigade =
+ apr_brigade_create(f->r->pool, f->r->connection->bucket_alloc);
+ while (!APR_BRIGADE_EMPTY(bb)) {
+ apr_size_t readlen;
+ const char *buffer;
- apr_bucket *e = APR_BRIGADE_FIRST(bb);
+ apr_bucket *e = APR_BRIGADE_FIRST(bb);
- if (APR_BUCKET_IS_EOS(e))
- break;
+ if (APR_BUCKET_IS_EOS(e))
+ break;
- if (APR_BUCKET_IS_METADATA(e)) {
- apr_bucket_delete(e);
- continue;
- }
+ if (APR_BUCKET_IS_METADATA(e)) {
+ apr_bucket_delete(e);
+ continue;
+ }
- /* Read the bucket now */
- if ((rv = apr_bucket_read(e, &buffer, &readlen,
- APR_BLOCK_READ)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_INFO, rv,
- main_server,
- "mod_fcgid: can't read data from fcgid handler");
- return rv;
- }
+ /* Read the bucket now */
+ if ((rv = apr_bucket_read(e, &buffer, &readlen,
+ APR_BLOCK_READ)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_INFO, rv,
+ main_server,
+ "mod_fcgid: can't read data from fcgid handler");
+ return rv;
+ }
- /* Move on to next bucket if it's fastcgi header bucket */
- if (e->type == &ap_bucket_type_fcgid_header
- || (e->type == &apr_bucket_type_immortal && readlen == 0)) {
- apr_bucket_delete(e);
- continue;
- }
- save_size += readlen;
+ /* Move on to next bucket if it's fastcgi header bucket */
+ if (e->type == &ap_bucket_type_fcgid_header
+ || (e->type == &apr_bucket_type_immortal && readlen == 0)) {
+ apr_bucket_delete(e);
+ continue;
+ }
+ save_size += readlen;
- /* Cache it to tmp_brigade */
- APR_BUCKET_REMOVE(e);
- APR_BRIGADE_INSERT_TAIL(tmp_brigade, e);
+ /* Cache it to tmp_brigade */
+ APR_BUCKET_REMOVE(e);
+ APR_BRIGADE_INSERT_TAIL(tmp_brigade, e);
- /* I will pass tmp_brigade to next filter if I have got too much buckets */
- if (save_size > g_buffsize) {
- APR_BRIGADE_INSERT_TAIL(tmp_brigade,
- apr_bucket_flush_create(f->r->
- connection->
- bucket_alloc));
+ /* I will pass tmp_brigade to next filter if I have got too much buckets */
+ if (save_size > g_buffsize) {
+ APR_BRIGADE_INSERT_TAIL(tmp_brigade,
+ apr_bucket_flush_create(f->r->
+ connection->
+ bucket_alloc));
- if ((rv =
- ap_pass_brigade(f->next, tmp_brigade)) != APR_SUCCESS)
- return rv;
+ if ((rv =
+ ap_pass_brigade(f->next, tmp_brigade)) != APR_SUCCESS)
+ return rv;
- /* Is the client aborted? */
- if (c && c->aborted)
- return APR_SUCCESS;
+ /* Is the client aborted? */
+ if (c && c->aborted)
+ return APR_SUCCESS;
- save_size = 0;
- }
- }
+ save_size = 0;
+ }
+ }
- /* Any thing left? */
- if (!APR_BRIGADE_EMPTY(tmp_brigade)) {
- if ((rv = ap_pass_brigade(f->next, tmp_brigade)) != APR_SUCCESS)
- return rv;
- }
+ /* Any thing left? */
+ if (!APR_BRIGADE_EMPTY(tmp_brigade)) {
+ if ((rv = ap_pass_brigade(f->next, tmp_brigade)) != APR_SUCCESS)
+ return rv;
+ }
- /* This filter is done once it has served up its content */
- ap_remove_output_filter(f);
- return APR_SUCCESS;
+ /* This filter is done once it has served up its content */
+ ap_remove_output_filter(f);
+ return APR_SUCCESS;
}
diff --git a/mod_fcgid/fcgid_pm.h b/mod_fcgid/fcgid_pm.h
index 4ec8c73..0dc6354 100644
--- a/mod_fcgid/fcgid_pm.h
+++ b/mod_fcgid/fcgid_pm.h
@@ -23,32 +23,32 @@
#define INITENV_CNT 64
typedef struct {
- char cgipath[_POSIX_PATH_MAX];
- char wrapperpath[_POSIX_PATH_MAX];
- apr_ino_t inode;
- dev_t deviceid;
- apr_size_t share_grp_id;
- char *virtualhost; /* Virtualhost granularity */
- uid_t uid; /* For suEXEC */
- gid_t gid; /* For suEXEC */
- int userdir; /* For suEXEC */
- char initenv_key[INITENV_CNT][INITENV_KEY_LEN];
- char initenv_val[INITENV_CNT][INITENV_VAL_LEN];
+ char cgipath[_POSIX_PATH_MAX];
+ char wrapperpath[_POSIX_PATH_MAX];
+ apr_ino_t inode;
+ dev_t deviceid;
+ apr_size_t share_grp_id;
+ char *virtualhost; /* Virtualhost granularity */
+ uid_t uid; /* For suEXEC */
+ gid_t gid; /* For suEXEC */
+ int userdir; /* For suEXEC */
+ char initenv_key[INITENV_CNT][INITENV_KEY_LEN];
+ char initenv_val[INITENV_CNT][INITENV_VAL_LEN];
} fcgid_command;
void procmgr_init_spawn_cmd(fcgid_command * command, request_rec * r,
- const char *argv0, dev_t deviceid,
- apr_ino_t inode, apr_size_t share_grp_id);
+ const char *argv0, dev_t deviceid,
+ apr_ino_t inode, apr_size_t share_grp_id);
apr_status_t procmgr_post_spawn_cmd(fcgid_command * command,
- request_rec * r);
+ request_rec * r);
apr_status_t procmgr_peek_cmd(fcgid_command * command,
- server_rec * main_server);
+ server_rec * main_server);
apr_status_t procmgr_finish_notify(server_rec * main_server);
apr_status_t procmgr_child_init(server_rec * main_server,
- apr_pool_t * pchild);
+ apr_pool_t * pchild);
apr_status_t procmgr_post_config(server_rec * main_server,
- apr_pool_t * pconf);
+ apr_pool_t * pconf);
apr_status_t procmgr_stop_procmgr(void *dummy);
int procmgr_must_exit(void);
diff --git a/mod_fcgid/fcgid_pm_main.c b/mod_fcgid/fcgid_pm_main.c
index fa35e7b..dc4e68a 100644
--- a/mod_fcgid/fcgid_pm_main.c
+++ b/mod_fcgid/fcgid_pm_main.c
@@ -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();
+ /*
+ 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;
+ /* 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();
+ /* 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;
+ 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;
+ /* 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;
+ /* 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);
+ 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();
+ /*
+ 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;
+ /* 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();
+ /* 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];
+ 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;
+ 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;
+ /* 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;
+ /* 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);
+ 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;
+ /*
+ 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));
+ 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;
+ /* 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;
+ /*
+ 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];
+ 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;
+ /* 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;
+ /* 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);
+ 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];
+ /*
+ 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);
+ /* 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;
+ /* 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;
+ /* 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;
- }
+ 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];
+ /*
+ 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];
- }
+ /* 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);
- }
+ /* 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;
+ /*
+ 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();
+ /* 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);
+ /* 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];
+ 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;
+ 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;
+ /* 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;
- }
+ 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);
- }
- }
+ /* 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);
+ /* 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();
+ 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 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);
- }
- }
+ /* 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;
- }
- }
- }
+ /* 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;
+ 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();
+ 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);
+ /* 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;
+ /* 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);
+ 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]);
- }
+ 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);
+ /* 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_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;
+ /* 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;
+ 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);
+ /* 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);
- }
+ procmgr_finish_notify(main_server);
+ }
- /* Move matched node to error list */
- scan_idlelist_zombie(main_server);
- scan_idlelist(main_server);
- scan_busylist(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);
- }
+ /* 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;
}
diff --git a/mod_fcgid/fcgid_proc.h b/mod_fcgid/fcgid_proc.h
index 8753bfc..af5cd4d 100644
--- a/mod_fcgid/fcgid_proc.h
+++ b/mod_fcgid/fcgid_proc.h
@@ -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
diff --git a/mod_fcgid/fcgid_proctbl.h b/mod_fcgid/fcgid_proctbl.h
index e64527e..4f431fa 100644
--- a/mod_fcgid/fcgid_proctbl.h
+++ b/mod_fcgid/fcgid_proctbl.h
@@ -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);
diff --git a/mod_fcgid/fcgid_protocol.c b/mod_fcgid/fcgid_protocol.c
index 55b7acd..b362355 100644
--- a/mod_fcgid/fcgid_protocol.c
+++ b/mod_fcgid/fcgid_protocol.c
@@ -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;
+ 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;
+ for (; *envp != NULL; envp++) {
+ spliter = strchr(*envp, '=');
+ if (spliter == NULL)
+ continue;
- namelen = spliter - *envp;
- valuelen = strlen(spliter + 1);
+ 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 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;
- }
- }
+ /* 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;
+ /* 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);
+ /* 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;
- }
+ /* 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);
+ /* 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);
+ /* 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);
+ /* 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;
- }
+ 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);
+ /* 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);
+ /* 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;
}
diff --git a/mod_fcgid/fcgid_protocol.h b/mod_fcgid/fcgid_protocol.h
index 5d5f3d3..454524c 100644
--- a/mod_fcgid/fcgid_protocol.h
+++ b/mod_fcgid/fcgid_protocol.h
@@ -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
diff --git a/mod_fcgid/fcgid_spawn_ctl.c b/mod_fcgid/fcgid_spawn_ctl.c
index c6c5bd2..97831c6 100644
--- a/mod_fcgid/fcgid_spawn_ctl.c
+++ b/mod_fcgid/fcgid_spawn_ctl.c
@@ -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;
- }
+ /* 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();
+ 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--;
- }
+ /* 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));
+ /* 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;
+ /* 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;
+ 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;
- }
+ /* 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);
- }
+ 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);
+ /* 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;
- }
+ /* 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();
+ 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;
+ 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;
- }
+ /* 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;
- }
+ /* 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;
- }
+ /*
+ 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;
- }
+ /* 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;
- }
+ if (current_node) {
+ /* Found the node */
+ if (current_node->process_counter <= g_min_class_process)
+ return 0;
+ }
- return 1;
+ return 1;
}
diff --git a/mod_fcgid/fcgid_spawn_ctl.h b/mod_fcgid/fcgid_spawn_ctl.h
index 1b28858..8daf95a 100644
--- a/mod_fcgid/fcgid_spawn_ctl.h
+++ b/mod_fcgid/fcgid_spawn_ctl.h
@@ -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);
diff --git a/mod_fcgid/mod_fcgid.c b/mod_fcgid/mod_fcgid.c
index 70b9e8c..a4c6de3 100644
--- a/mod_fcgid/mod_fcgid.c
+++ b/mod_fcgid/mod_fcgid.c
@@ -48,624 +48,624 @@
static int is_scriptaliased(request_rec * r)
{
- const char *t = apr_table_get(r->notes, "alias-forced-type");
+ const char *t = apr_table_get(r->notes, "alias-forced-type");
- return t && (!strcasecmp(t, "cgi-script"));
+ return t && (!strcasecmp(t, "cgi-script"));
}
static apr_status_t
default_build_command(const char **cmd, const char ***argv,
- request_rec * r, apr_pool_t * p,
- cgi_exec_info_t * e_info)
+ request_rec * r, apr_pool_t * p,
+ cgi_exec_info_t * e_info)
{
- int numwords, x, idx;
- char *w;
- const char *args = NULL;
+ int numwords, x, idx;
+ char *w;
+ const char *args = NULL;
- if (e_info->process_cgi) {
- *cmd = r->filename;
- /* Do not process r->args if they contain an '=' assignment
- */
- if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
- args = r->args;
- }
- }
+ if (e_info->process_cgi) {
+ *cmd = r->filename;
+ /* Do not process r->args if they contain an '=' assignment
+ */
+ if (r->args && r->args[0] && !ap_strchr_c(r->args, '=')) {
+ args = r->args;
+ }
+ }
- if (!args) {
- numwords = 1;
- } else {
- /* count the number of keywords */
- for (x = 0, numwords = 2; args[x]; x++) {
- if (args[x] == '+') {
- ++numwords;
- }
- }
- }
- /* Everything is - 1 to account for the first parameter
- * which is the program name.
- */
- if (numwords > APACHE_ARG_MAX - 1) {
- numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */
- }
- *argv = apr_palloc(p, (numwords + 2) * sizeof(char *));
- (*argv)[0] = *cmd;
- for (x = 1, idx = 1; x < numwords; x++) {
- w = ap_getword_nulls(p, &args, '+');
- ap_unescape_url(w);
- (*argv)[idx++] = ap_escape_shell_cmd(p, w);
- }
- (*argv)[idx] = NULL;
+ if (!args) {
+ numwords = 1;
+ } else {
+ /* count the number of keywords */
+ for (x = 0, numwords = 2; args[x]; x++) {
+ if (args[x] == '+') {
+ ++numwords;
+ }
+ }
+ }
+ /* Everything is - 1 to account for the first parameter
+ * which is the program name.
+ */
+ if (numwords > APACHE_ARG_MAX - 1) {
+ numwords = APACHE_ARG_MAX - 1; /* Truncate args to prevent overrun */
+ }
+ *argv = apr_palloc(p, (numwords + 2) * sizeof(char *));
+ (*argv)[0] = *cmd;
+ for (x = 1, idx = 1; x < numwords; x++) {
+ w = ap_getword_nulls(p, &args, '+');
+ ap_unescape_url(w);
+ (*argv)[idx++] = ap_escape_shell_cmd(p, w);
+ }
+ (*argv)[idx] = NULL;
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
/* End of stolen */
static void fcgid_add_cgi_vars(request_rec * r)
{
- apr_array_header_t *passheaders = get_pass_headers(r);
+ apr_array_header_t *passheaders = get_pass_headers(r);
- if (passheaders != NULL) {
- const char **hdr = (const char **) passheaders->elts;
- int hdrcnt = passheaders->nelts;
- int i;
+ if (passheaders != NULL) {
+ const char **hdr = (const char **) passheaders->elts;
+ int hdrcnt = passheaders->nelts;
+ int i;
- for (i = 0; i < hdrcnt; i++, ++hdr) {
- const char *val = apr_table_get(r->headers_in, *hdr);
+ for (i = 0; i < hdrcnt; i++, ++hdr) {
+ const char *val = apr_table_get(r->headers_in, *hdr);
- if (val)
- apr_table_setn(r->subprocess_env, *hdr, val);
- }
- }
+ if (val)
+ apr_table_setn(r->subprocess_env, *hdr, val);
+ }
+ }
- /* Work around cgi.fix_pathinfo = 1 in php.ini */
- if (g_php_fix_pathinfo_enable) {
- char *merge_path;
- apr_table_t *e = r->subprocess_env;
+ /* Work around cgi.fix_pathinfo = 1 in php.ini */
+ if (g_php_fix_pathinfo_enable) {
+ char *merge_path;
+ apr_table_t *e = r->subprocess_env;
- /* "DOCUMENT_ROOT"/"SCRIPT_NAME" -> "SCRIPT_NAME" */
- const char *doc_root = apr_table_get(e, "DOCUMENT_ROOT");
- const char *script_name = apr_table_get(e, "SCRIPT_NAME");
+ /* "DOCUMENT_ROOT"/"SCRIPT_NAME" -> "SCRIPT_NAME" */
+ const char *doc_root = apr_table_get(e, "DOCUMENT_ROOT");
+ const char *script_name = apr_table_get(e, "SCRIPT_NAME");
- if (doc_root && script_name
- && apr_filepath_merge(&merge_path, doc_root, script_name, 0,
- r->pool) == APR_SUCCESS) {
- apr_table_setn(e, "SCRIPT_NAME", merge_path);
- }
- }
+ if (doc_root && script_name
+ && apr_filepath_merge(&merge_path, doc_root, script_name, 0,
+ r->pool) == APR_SUCCESS) {
+ apr_table_setn(e, "SCRIPT_NAME", merge_path);
+ }
+ }
}
static int fcgid_handler(request_rec * r)
{
- cgi_exec_info_t e_info;
- const char *command;
- const char **argv;
- apr_pool_t *p;
- apr_status_t rv;
- int http_retcode;
- fcgid_wrapper_conf *wrapper_conf;
+ cgi_exec_info_t e_info;
+ const char *command;
+ const char **argv;
+ apr_pool_t *p;
+ apr_status_t rv;
+ int http_retcode;
+ fcgid_wrapper_conf *wrapper_conf;
- if (strcmp(r->handler, "fcgid-script"))
- return DECLINED;
+ if (strcmp(r->handler, "fcgid-script"))
+ return DECLINED;
- if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r))
- return HTTP_FORBIDDEN;
+ if (!(ap_allow_options(r) & OPT_EXECCGI) && !is_scriptaliased(r))
+ return HTTP_FORBIDDEN;
- if (r->finfo.filetype == 0)
- return HTTP_NOT_FOUND;
+ if (r->finfo.filetype == 0)
+ return HTTP_NOT_FOUND;
- if (r->finfo.filetype == APR_DIR)
- return HTTP_FORBIDDEN;
+ if (r->finfo.filetype == APR_DIR)
+ return HTTP_FORBIDDEN;
- if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) &&
- r->path_info && *r->path_info)
- return HTTP_NOT_FOUND;
+ if ((r->used_path_info == AP_REQ_REJECT_PATH_INFO) &&
+ r->path_info && *r->path_info)
+ return HTTP_NOT_FOUND;
- e_info.process_cgi = 1;
- e_info.cmd_type = APR_PROGRAM;
- e_info.detached = 0;
- e_info.in_pipe = APR_CHILD_BLOCK;
- e_info.out_pipe = APR_CHILD_BLOCK;
- e_info.err_pipe = APR_CHILD_BLOCK;
- e_info.prog_type = RUN_AS_CGI;
- e_info.bb = NULL;
- e_info.ctx = NULL;
- e_info.next = NULL;
- p = r->main ? r->main->pool : r->pool;
+ e_info.process_cgi = 1;
+ e_info.cmd_type = APR_PROGRAM;
+ e_info.detached = 0;
+ e_info.in_pipe = APR_CHILD_BLOCK;
+ e_info.out_pipe = APR_CHILD_BLOCK;
+ e_info.err_pipe = APR_CHILD_BLOCK;
+ e_info.prog_type = RUN_AS_CGI;
+ e_info.bb = NULL;
+ e_info.ctx = NULL;
+ e_info.next = NULL;
+ p = r->main ? r->main->pool : r->pool;
- /* Build the command line */
- if ((wrapper_conf = get_wrapper_info(r->filename, r))) {
- if ((rv =
- default_build_command(&command, &argv, r, p,
- &e_info)) != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
- "mod_fcgid: don't know how to spawn wrapper child process: %s",
- r->filename);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- } else if ((rv =
- cgi_build_command(&command, &argv, r, p,
- &e_info)) != APR_SUCCESS) {
- ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
- "mod_fcgid: don't know how to spawn child process: %s",
- r->filename);
- return HTTP_INTERNAL_SERVER_ERROR;
- }
+ /* Build the command line */
+ if ((wrapper_conf = get_wrapper_info(r->filename, r))) {
+ if ((rv =
+ default_build_command(&command, &argv, r, p,
+ &e_info)) != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+ "mod_fcgid: don't know how to spawn wrapper child process: %s",
+ r->filename);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
+ } else if ((rv =
+ cgi_build_command(&command, &argv, r, p,
+ &e_info)) != APR_SUCCESS) {
+ ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
+ "mod_fcgid: don't know how to spawn child process: %s",
+ r->filename);
+ return HTTP_INTERNAL_SERVER_ERROR;
+ }
- /* Check request like "http://localhost/cgi-bin/a.exe/defghi" */
- if (!wrapper_conf && r->finfo.inode == 0 && r->finfo.device == 0) {
- if ((rv =
- apr_stat(&r->finfo, command, APR_FINFO_IDENT,
- r->pool)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
- "mod_fcgid: can't get %s file info", command);
- return HTTP_NOT_FOUND;
- }
- }
+ /* Check request like "http://localhost/cgi-bin/a.exe/defghi" */
+ if (!wrapper_conf && r->finfo.inode == 0 && r->finfo.device == 0) {
+ if ((rv =
+ apr_stat(&r->finfo, command, APR_FINFO_IDENT,
+ r->pool)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
+ "mod_fcgid: can't get %s file info", command);
+ return HTTP_NOT_FOUND;
+ }
+ }
- ap_add_common_vars(r);
- ap_add_cgi_vars(r);
- fcgid_add_cgi_vars(r);
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+ fcgid_add_cgi_vars(r);
- /* Insert output filter */
- ap_add_output_filter_handle(fcgid_filter_handle, NULL, r,
- r->connection);
+ /* Insert output filter */
+ ap_add_output_filter_handle(fcgid_filter_handle, NULL, r,
+ r->connection);
- http_retcode =
- bridge_request(r, FCGI_RESPONDER, command, wrapper_conf);
- return (http_retcode == HTTP_OK ? OK : http_retcode);
+ http_retcode =
+ bridge_request(r, FCGI_RESPONDER, command, wrapper_conf);
+ return (http_retcode == HTTP_OK ? OK : http_retcode);
}
static int mod_fcgid_modify_auth_header(void *subprocess_env,
- const char *key, const char *val)
+ const char *key, const char *val)
{
- /* When the application gives a 200 response, the server ignores response
- headers whose names aren't prefixed with Variable- prefix, and ignores
- any response content */
- if (strncasecmp(key, "Variable-", 9) == 0)
- apr_table_setn(subprocess_env, key + 9, val);
- return 1;
+ /* When the application gives a 200 response, the server ignores response
+ headers whose names aren't prefixed with Variable- prefix, and ignores
+ any response content */
+ if (strncasecmp(key, "Variable-", 9) == 0)
+ apr_table_setn(subprocess_env, key + 9, val);
+ return 1;
}
static int mod_fcgid_authenticator(request_rec * r)
{
- int res = 0;
- const char *password = NULL;
- const char *location = NULL;
- apr_table_t *saved_subprocess_env = NULL;
- fcgid_wrapper_conf *wrapper_conf;
- auth_conf *authenticator_info;
- int authoritative;
+ int res = 0;
+ const char *password = NULL;
+ const char *location = NULL;
+ apr_table_t *saved_subprocess_env = NULL;
+ fcgid_wrapper_conf *wrapper_conf;
+ auth_conf *authenticator_info;
+ int authoritative;
- authenticator_info = get_authenticator_info(r, &authoritative);
+ authenticator_info = get_authenticator_info(r, &authoritative);
- /* Is authenticator enable? */
- if (authenticator_info == NULL)
- return DECLINED;
+ /* Is authenticator enable? */
+ if (authenticator_info == NULL)
+ return DECLINED;
- /* Check wrapper */
- wrapper_conf = get_wrapper_info(authenticator_info->path, r);
+ /* Check wrapper */
+ wrapper_conf = get_wrapper_info(authenticator_info->path, r);
- /* Get the user password */
- if ((res = ap_get_basic_auth_pw(r, &password)) != OK)
- return res;
+ /* Get the user password */
+ if ((res = ap_get_basic_auth_pw(r, &password)) != OK)
+ return res;
- /* Save old process environment */
- saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
+ /* Save old process environment */
+ saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
- /* Add some environment variables */
- ap_add_common_vars(r);
- ap_add_cgi_vars(r);
- fcgid_add_cgi_vars(r);
- apr_table_setn(r->subprocess_env, "REMOTE_PASSWD", password);
- apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE", "AUTHENTICATOR");
+ /* Add some environment variables */
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+ fcgid_add_cgi_vars(r);
+ apr_table_setn(r->subprocess_env, "REMOTE_PASSWD", password);
+ apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE", "AUTHENTICATOR");
- /* Remove some environment variables */
- /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
- apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
- apr_table_unset(r->subprocess_env, "PATH_INFO");
- apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
- apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
+ /* Remove some environment variables */
+ /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
+ apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
+ apr_table_unset(r->subprocess_env, "PATH_INFO");
+ apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
+ apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
- /* Handle the request */
- res =
- bridge_request(r, FCGI_AUTHORIZER, authenticator_info->path,
- wrapper_conf);
+ /* Handle the request */
+ res =
+ bridge_request(r, FCGI_AUTHORIZER, authenticator_info->path,
+ wrapper_conf);
- /* Restore r->subprocess_env */
- r->subprocess_env = saved_subprocess_env;
+ /* Restore r->subprocess_env */
+ r->subprocess_env = saved_subprocess_env;
- if (res == OK && r->status == 200
- && (location = apr_table_get(r->headers_out, "Location")) == NULL)
- {
- /* Pass */
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s authentication pass", r->user);
+ if (res == OK && r->status == 200
+ && (location = apr_table_get(r->headers_out, "Location")) == NULL)
+ {
+ /* Pass */
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s authentication pass", r->user);
- /* Modify headers: An Authorizer application's 200 response may include headers
- whose names are prefixed with Variable-. */
- apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
- r->err_headers_out, NULL);
+ /* Modify headers: An Authorizer application's 200 response may include headers
+ whose names are prefixed with Variable-. */
+ apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
+ r->err_headers_out, NULL);
- return OK;
- } else {
- /* Print error info first */
- if (res != OK)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s authentication failed, respond %d, URI %s",
- r->user, res, r->uri);
- else if (r->status != 200)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s authentication failed, status %d, URI %s",
- r->user, r->status, r->uri);
- else
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s authentication failed, redirected is not allowed",
- r->user);
+ return OK;
+ } else {
+ /* Print error info first */
+ if (res != OK)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s authentication failed, respond %d, URI %s",
+ r->user, res, r->uri);
+ else if (r->status != 200)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s authentication failed, status %d, URI %s",
+ r->user, r->status, r->uri);
+ else
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s authentication failed, redirected is not allowed",
+ r->user);
- /* Handle error */
- if (!authoritative)
- return DECLINED;
- else {
- ap_note_basic_auth_failure(r);
- return (res == OK) ? HTTP_UNAUTHORIZED : res;
- }
- }
+ /* Handle error */
+ if (!authoritative)
+ return DECLINED;
+ else {
+ ap_note_basic_auth_failure(r);
+ return (res == OK) ? HTTP_UNAUTHORIZED : res;
+ }
+ }
}
static int mod_fcgid_authorizer(request_rec * r)
{
- int res = 0;
- const char *location = NULL;
- apr_table_t *saved_subprocess_env = NULL;
- fcgid_wrapper_conf *wrapper_conf;
- auth_conf *authorizer_info;
- int authoritative;
+ int res = 0;
+ const char *location = NULL;
+ apr_table_t *saved_subprocess_env = NULL;
+ fcgid_wrapper_conf *wrapper_conf;
+ auth_conf *authorizer_info;
+ int authoritative;
- authorizer_info = get_authorizer_info(r, &authoritative);
+ authorizer_info = get_authorizer_info(r, &authoritative);
- /* Is authenticator enable? */
- if (authorizer_info == NULL)
- return DECLINED;
+ /* Is authenticator enable? */
+ if (authorizer_info == NULL)
+ return DECLINED;
- /* Check wrapper */
- wrapper_conf = get_wrapper_info(authorizer_info->path, r);
+ /* Check wrapper */
+ wrapper_conf = get_wrapper_info(authorizer_info->path, r);
- /* Save old process environment */
- saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
+ /* Save old process environment */
+ saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
- /* Add some environment variables */
- ap_add_common_vars(r);
- ap_add_cgi_vars(r);
- fcgid_add_cgi_vars(r);
- apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE", "AUTHORIZER");
+ /* Add some environment variables */
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+ fcgid_add_cgi_vars(r);
+ apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE", "AUTHORIZER");
- /* Remove some environment variables */
- /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
- apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
- apr_table_unset(r->subprocess_env, "PATH_INFO");
- apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
- apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
+ /* Remove some environment variables */
+ /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
+ apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
+ apr_table_unset(r->subprocess_env, "PATH_INFO");
+ apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
+ apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
- /* Handle the request */
- res =
- bridge_request(r, FCGI_AUTHORIZER, authorizer_info->path,
- wrapper_conf);
+ /* Handle the request */
+ res =
+ bridge_request(r, FCGI_AUTHORIZER, authorizer_info->path,
+ wrapper_conf);
- /* Restore r->subprocess_env */
- r->subprocess_env = saved_subprocess_env;
+ /* Restore r->subprocess_env */
+ r->subprocess_env = saved_subprocess_env;
- if (res == OK && r->status == 200
- && (location = apr_table_get(r->headers_out, "Location")) == NULL)
- {
- /* Pass */
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
- "mod_fcgid: access granted");
+ if (res == OK && r->status == 200
+ && (location = apr_table_get(r->headers_out, "Location")) == NULL)
+ {
+ /* Pass */
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: access granted");
- /* Modify headers: An Authorizer application's 200 response may include headers
- whose names are prefixed with Variable-. */
- apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
- r->err_headers_out, NULL);
+ /* Modify headers: An Authorizer application's 200 response may include headers
+ whose names are prefixed with Variable-. */
+ apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
+ r->err_headers_out, NULL);
- return OK;
- } else {
- /* Print error info first */
- if (res != OK)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, respond %d, URI %s",
- r->user, res, r->uri);
- else if (r->status != 200)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, status %d, URI %s",
- r->user, r->status, r->uri);
- else
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, redirected is not allowed",
- r->user);
+ return OK;
+ } else {
+ /* Print error info first */
+ if (res != OK)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, respond %d, URI %s",
+ r->user, res, r->uri);
+ else if (r->status != 200)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, status %d, URI %s",
+ r->user, r->status, r->uri);
+ else
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, redirected is not allowed",
+ r->user);
- /* Handle error */
- if (!authoritative)
- return DECLINED;
- else {
- ap_note_basic_auth_failure(r);
- return (res == OK) ? HTTP_UNAUTHORIZED : res;
- }
- }
+ /* Handle error */
+ if (!authoritative)
+ return DECLINED;
+ else {
+ ap_note_basic_auth_failure(r);
+ return (res == OK) ? HTTP_UNAUTHORIZED : res;
+ }
+ }
}
static int mod_fcgid_check_access(request_rec * r)
{
- int res = 0;
- const char *location = NULL;
- apr_table_t *saved_subprocess_env = NULL;
- fcgid_wrapper_conf *wrapper_conf;
- auth_conf *access_info;
- int authoritative;
+ int res = 0;
+ const char *location = NULL;
+ apr_table_t *saved_subprocess_env = NULL;
+ fcgid_wrapper_conf *wrapper_conf;
+ auth_conf *access_info;
+ int authoritative;
- access_info = get_access_info(r, &authoritative);
+ access_info = get_access_info(r, &authoritative);
- /* Is access check enable? */
- if (access_info == NULL)
- return DECLINED;
+ /* Is access check enable? */
+ if (access_info == NULL)
+ return DECLINED;
- /* Check wrapper */
- wrapper_conf = get_wrapper_info(access_info->path, r);
+ /* Check wrapper */
+ wrapper_conf = get_wrapper_info(access_info->path, r);
- /* Save old process environment */
- saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
+ /* Save old process environment */
+ saved_subprocess_env = apr_table_copy(r->pool, r->subprocess_env);
- /* Add some environment variables */
- ap_add_common_vars(r);
- ap_add_cgi_vars(r);
- fcgid_add_cgi_vars(r);
- apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE",
- "ACCESS_CHECKER");
+ /* Add some environment variables */
+ ap_add_common_vars(r);
+ ap_add_cgi_vars(r);
+ fcgid_add_cgi_vars(r);
+ apr_table_setn(r->subprocess_env, "FCGI_APACHE_ROLE",
+ "ACCESS_CHECKER");
- /* Remove some environment variables */
- /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
- apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
- apr_table_unset(r->subprocess_env, "PATH_INFO");
- apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
- apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
+ /* Remove some environment variables */
+ /* The Web server does not send CONTENT_LENGTH, PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME headers */
+ apr_table_unset(r->subprocess_env, "CONTENT_LENGTH");
+ apr_table_unset(r->subprocess_env, "PATH_INFO");
+ apr_table_unset(r->subprocess_env, "PATH_TRANSLATED");
+ apr_table_unset(r->subprocess_env, "SCRIPT_NAME");
- /* Handle the request */
- res =
- bridge_request(r, FCGI_AUTHORIZER, access_info->path,
- wrapper_conf);
+ /* Handle the request */
+ res =
+ bridge_request(r, FCGI_AUTHORIZER, access_info->path,
+ wrapper_conf);
- /* Restore r->subprocess_env */
- r->subprocess_env = saved_subprocess_env;
+ /* Restore r->subprocess_env */
+ r->subprocess_env = saved_subprocess_env;
- if (res == OK && r->status == 200
- && (location = apr_table_get(r->headers_out, "Location")) == NULL)
- {
- /* Pass */
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
- "mod_fcgid: access check pass");
+ if (res == OK && r->status == 200
+ && (location = apr_table_get(r->headers_out, "Location")) == NULL)
+ {
+ /* Pass */
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: access check pass");
- /* Modify headers: An Authorizer application's 200 response may include headers
- whose names are prefixed with Variable-. */
- apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
- r->err_headers_out, NULL);
+ /* Modify headers: An Authorizer application's 200 response may include headers
+ whose names are prefixed with Variable-. */
+ apr_table_do(mod_fcgid_modify_auth_header, r->subprocess_env,
+ r->err_headers_out, NULL);
- return OK;
- } else {
- /* Print error info first */
- if (res != OK)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, respond %d, URI %s",
- r->user, res, r->uri);
- else if (r->status != 200)
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, status %d, URI %s",
- r->user, r->status, r->uri);
- else
- ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
- "mod_fcgid: user %s access check failed, redirected is not allowed",
- r->user);
+ return OK;
+ } else {
+ /* Print error info first */
+ if (res != OK)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, respond %d, URI %s",
+ r->user, res, r->uri);
+ else if (r->status != 200)
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, status %d, URI %s",
+ r->user, r->status, r->uri);
+ else
+ ap_log_rerror(APLOG_MARK, APLOG_WARNING | APLOG_NOERRNO, 0, r,
+ "mod_fcgid: user %s access check failed, redirected is not allowed",
+ r->user);
- /* Handle error */
- if (!authoritative)
- return DECLINED;
- else {
- ap_note_basic_auth_failure(r);
- return (res == OK) ? HTTP_UNAUTHORIZED : res;
- }
- }
+ /* Handle error */
+ if (!authoritative)
+ return DECLINED;
+ else {
+ ap_note_basic_auth_failure(r);
+ return (res == OK) ? HTTP_UNAUTHORIZED : res;
+ }
+ }
}
static void initialize_child(apr_pool_t * pchild, server_rec * main_server)
{
- apr_status_t rv;
+ apr_status_t rv;
- if ((rv = proctable_child_init(main_server, pchild)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't initialize share memory or mutex in child");
- return;
- }
+ if ((rv = proctable_child_init(main_server, pchild)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't initialize share memory or mutex in child");
+ return;
+ }
- if ((rv = procmgr_child_init(main_server, pchild)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't initialize process manager");
- return;
- }
+ if ((rv = procmgr_child_init(main_server, pchild)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't initialize process manager");
+ return;
+ }
- return;
+ return;
}
static int
fcgid_init(apr_pool_t * config_pool, apr_pool_t * plog, apr_pool_t * ptemp,
- server_rec * main_server)
+ server_rec * main_server)
{
- apr_proc_t *procnew;
- const char *userdata_key = "fcgid_init";
- apr_status_t rv;
- void *dummy = NULL;
+ apr_proc_t *procnew;
+ const char *userdata_key = "fcgid_init";
+ apr_status_t rv;
+ void *dummy = NULL;
- g_php_fix_pathinfo_enable = get_php_fix_pathinfo_enable(main_server);
+ g_php_fix_pathinfo_enable = get_php_fix_pathinfo_enable(main_server);
- /* Initialize process manager only once */
- apr_pool_userdata_get(&dummy, userdata_key,
- main_server->process->pool);
- if (!dummy) {
- procnew =
- apr_pcalloc(main_server->process->pool, sizeof(*procnew));
- procnew->pid = -1;
- procnew->err = procnew->in = procnew->out = NULL;
- apr_pool_userdata_set((const void *) procnew, userdata_key,
- apr_pool_cleanup_null,
- main_server->process->pool);
- return OK;
- } else {
- procnew = dummy;
- }
+ /* Initialize process manager only once */
+ apr_pool_userdata_get(&dummy, userdata_key,
+ main_server->process->pool);
+ if (!dummy) {
+ procnew =
+ apr_pcalloc(main_server->process->pool, sizeof(*procnew));
+ procnew->pid = -1;
+ procnew->err = procnew->in = procnew->out = NULL;
+ apr_pool_userdata_set((const void *) procnew, userdata_key,
+ apr_pool_cleanup_null,
+ main_server->process->pool);
+ return OK;
+ } else {
+ procnew = dummy;
+ }
- /* Initialize share memory and share lock */
- if ((rv =
- proctable_post_config(main_server, config_pool)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't initialize share memory or mutex");
- return rv;
- }
+ /* Initialize share memory and share lock */
+ if ((rv =
+ proctable_post_config(main_server, config_pool)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't initialize share memory or mutex");
+ return rv;
+ }
- /* Initialize process manager */
- if ((rv =
- procmgr_post_config(main_server, config_pool)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
- "mod_fcgid: Can't initialize process manager");
- return rv;
- }
+ /* Initialize process manager */
+ if ((rv =
+ procmgr_post_config(main_server, config_pool)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, main_server,
+ "mod_fcgid: Can't initialize process manager");
+ return rv;
+ }
- /* This is the means by which unusual (non-unix) os's may find alternate
- * means to run a given command (e.g. shebang/registry parsing on Win32)
- */
- cgi_build_command = APR_RETRIEVE_OPTIONAL_FN(ap_cgi_build_command);
- if (!cgi_build_command) {
- cgi_build_command = default_build_command;
- }
+ /* This is the means by which unusual (non-unix) os's may find alternate
+ * means to run a given command (e.g. shebang/registry parsing on Win32)
+ */
+ cgi_build_command = APR_RETRIEVE_OPTIONAL_FN(ap_cgi_build_command);
+ if (!cgi_build_command) {
+ cgi_build_command = default_build_command;
+ }
- return APR_SUCCESS;
+ return APR_SUCCESS;
}
static const command_rec fcgid_cmds[] = {
- AP_INIT_TAKE1("IdleTimeout", set_idle_timeout, NULL, RSRC_CONF,
- "an idle fastcgi application will be killed after IdleTimeout"),
- AP_INIT_TAKE1("IdleScanInterval", set_idle_scan_interval, NULL,
- RSRC_CONF,
- "scan interval for idle timeout process"),
- AP_INIT_TAKE1("BusyTimeout", set_busy_timeout, NULL, RSRC_CONF,
- "a fastcgi application will be killed after handling a request for BusyTimeout"),
- AP_INIT_TAKE1("BusyScanInterval", set_busy_scan_interval, NULL,
- RSRC_CONF,
- "scan interval for busy timeout process"),
- AP_INIT_TAKE1("ErrorScanInterval", set_error_scan_interval, NULL,
- RSRC_CONF,
- "scan interval for exited process"),
- AP_INIT_TAKE1("ZombieScanInterval", set_zombie_scan_interval, NULL,
- RSRC_CONF,
- "scan interval for zombiz process"),
- AP_INIT_TAKE1("ProcessLifeTime", set_proc_lifetime, NULL, RSRC_CONF,
- "fastcgi application lifetime"),
- AP_INIT_TAKE1("SocketPath", set_socketpath, NULL, RSRC_CONF,
- "fastcgi socket file path"),
- AP_INIT_TAKE1("SharememPath", set_shmpath, NULL, RSRC_CONF,
- "fastcgi share memory file path"),
- AP_INIT_TAKE1("SpawnScoreUpLimit", set_spawnscore_uplimit, NULL,
- RSRC_CONF,
- "Spawn score up limit"),
- AP_INIT_TAKE1("SpawnScore", set_spawn_score, NULL, RSRC_CONF,
- "Score of spawn"),
- AP_INIT_TAKE1("TimeScore", set_time_score, NULL,
- RSRC_CONF,
- "Score of passage of time (in seconds)"),
- AP_INIT_TAKE1("TerminationScore", set_termination_score, NULL,
- RSRC_CONF,
- "Score of termination"),
- AP_INIT_TAKE1("MaxProcessCount", set_max_process, NULL, RSRC_CONF,
- "Max total process count"),
- AP_INIT_TAKE1("DefaultMaxClassProcessCount",
- set_max_class_process,
- NULL, RSRC_CONF,
- "Max process count of one class of fastcgi application"),
- AP_INIT_TAKE1("DefaultMinClassProcessCount",
- set_min_class_process,
- NULL, RSRC_CONF,
- "Min process count of one class of fastcgi application"),
- AP_INIT_TAKE1("OutputBufferSize", set_output_buffersize, NULL,
- RSRC_CONF,
- "CGI output buffer size"),
- AP_INIT_TAKE1("IPCConnectTimeout", set_ipc_connect_timeout, NULL,
- RSRC_CONF,
- "Connect timeout to fastcgi server"),
- AP_INIT_TAKE1("IPCCommTimeout", set_ipc_comm_timeout, NULL, RSRC_CONF,
- "Communication timeout to fastcgi server"),
- AP_INIT_TAKE1("MaxRequestLen", set_max_request_len, NULL, RSRC_CONF,
- "Max HTTP request length in byte"),
- AP_INIT_TAKE1("MaxRequestInMem", set_max_mem_request_len, NULL,
- RSRC_CONF,
- "The part of HTTP request which greater than this limit will swap to disk"),
- AP_INIT_TAKE12("DefaultInitEnv", add_default_env_vars, NULL, RSRC_CONF,
- "an environment variable name and optional value to pass to FastCGI."),
- AP_INIT_TAKE1("PassHeader", add_pass_headers, NULL, RSRC_CONF,
- "Header name which will be passed to FastCGI as environment variable."),
- AP_INIT_TAKE12("FCGIWrapper", set_wrapper_config, NULL,
- RSRC_CONF | ACCESS_CONF | OR_FILEINFO,
- "The CGI wrapper setting"),
- AP_INIT_TAKE1("PHP_Fix_Pathinfo_Enable",
- set_php_fix_pathinfo_enable,
- NULL, RSRC_CONF,
- "Set 1, if cgi.fix_pathinfo=1 in php.ini"),
- AP_INIT_TAKE1("MaxRequestsPerProcess", set_max_requests_per_process,
- NULL, RSRC_CONF,
- "Max requests handled by each fastcgi application"),
- AP_INIT_TAKE1("FastCgiAuthenticator", set_authenticator_info, NULL,
- ACCESS_CONF | OR_FILEINFO,
- "a absolute authenticator file path"),
- AP_INIT_FLAG("FastCgiAuthenticatorAuthoritative",
- set_authenticator_authoritative, NULL,
- ACCESS_CONF | OR_FILEINFO,
- "Set to 'off' to allow authentication to be passed along to lower modules upon failure"),
- AP_INIT_TAKE1("FastCgiAuthorizer", set_authorizer_info, NULL,
- ACCESS_CONF | OR_FILEINFO,
- "a absolute authorizer file path"),
- AP_INIT_FLAG("FastCgiAuthorizerAuthoritative",
- set_authorizer_authoritative, NULL,
- ACCESS_CONF | OR_FILEINFO,
- "Set to 'off' to allow authorization to be passed along to lower modules upon failure"),
- AP_INIT_TAKE1("FastCgiAccessChecker", set_access_info, NULL,
- ACCESS_CONF | OR_FILEINFO,
- "a absolute access checker file path"),
- AP_INIT_FLAG("FastCgiAccessCheckerAuthoritative",
- set_access_authoritative, NULL, ACCESS_CONF | OR_FILEINFO,
- "Set to 'off' to allow access control to be passed along to lower modules upon failure"),
- {NULL}
+ AP_INIT_TAKE1("IdleTimeout", set_idle_timeout, NULL, RSRC_CONF,
+ "an idle fastcgi application will be killed after IdleTimeout"),
+ AP_INIT_TAKE1("IdleScanInterval", set_idle_scan_interval, NULL,
+ RSRC_CONF,
+ "scan interval for idle timeout process"),
+ AP_INIT_TAKE1("BusyTimeout", set_busy_timeout, NULL, RSRC_CONF,
+ "a fastcgi application will be killed after handling a request for BusyTimeout"),
+ AP_INIT_TAKE1("BusyScanInterval", set_busy_scan_interval, NULL,
+ RSRC_CONF,
+ "scan interval for busy timeout process"),
+ AP_INIT_TAKE1("ErrorScanInterval", set_error_scan_interval, NULL,
+ RSRC_CONF,
+ "scan interval for exited process"),
+ AP_INIT_TAKE1("ZombieScanInterval", set_zombie_scan_interval, NULL,
+ RSRC_CONF,
+ "scan interval for zombiz process"),
+ AP_INIT_TAKE1("ProcessLifeTime", set_proc_lifetime, NULL, RSRC_CONF,
+ "fastcgi application lifetime"),
+ AP_INIT_TAKE1("SocketPath", set_socketpath, NULL, RSRC_CONF,
+ "fastcgi socket file path"),
+ AP_INIT_TAKE1("SharememPath", set_shmpath, NULL, RSRC_CONF,
+ "fastcgi share memory file path"),
+ AP_INIT_TAKE1("SpawnScoreUpLimit", set_spawnscore_uplimit, NULL,
+ RSRC_CONF,
+ "Spawn score up limit"),
+ AP_INIT_TAKE1("SpawnScore", set_spawn_score, NULL, RSRC_CONF,
+ "Score of spawn"),
+ AP_INIT_TAKE1("TimeScore", set_time_score, NULL,
+ RSRC_CONF,
+ "Score of passage of time (in seconds)"),
+ AP_INIT_TAKE1("TerminationScore", set_termination_score, NULL,
+ RSRC_CONF,
+ "Score of termination"),
+ AP_INIT_TAKE1("MaxProcessCount", set_max_process, NULL, RSRC_CONF,
+ "Max total process count"),
+ AP_INIT_TAKE1("DefaultMaxClassProcessCount",
+ set_max_class_process,
+ NULL, RSRC_CONF,
+ "Max process count of one class of fastcgi application"),
+ AP_INIT_TAKE1("DefaultMinClassProcessCount",
+ set_min_class_process,
+ NULL, RSRC_CONF,
+ "Min process count of one class of fastcgi application"),
+ AP_INIT_TAKE1("OutputBufferSize", set_output_buffersize, NULL,
+ RSRC_CONF,
+ "CGI output buffer size"),
+ AP_INIT_TAKE1("IPCConnectTimeout", set_ipc_connect_timeout, NULL,
+ RSRC_CONF,
+ "Connect timeout to fastcgi server"),
+ AP_INIT_TAKE1("IPCCommTimeout", set_ipc_comm_timeout, NULL, RSRC_CONF,
+ "Communication timeout to fastcgi server"),
+ AP_INIT_TAKE1("MaxRequestLen", set_max_request_len, NULL, RSRC_CONF,
+ "Max HTTP request length in byte"),
+ AP_INIT_TAKE1("MaxRequestInMem", set_max_mem_request_len, NULL,
+ RSRC_CONF,
+ "The part of HTTP request which greater than this limit will swap to disk"),
+ AP_INIT_TAKE12("DefaultInitEnv", add_default_env_vars, NULL, RSRC_CONF,
+ "an environment variable name and optional value to pass to FastCGI."),
+ AP_INIT_TAKE1("PassHeader", add_pass_headers, NULL, RSRC_CONF,
+ "Header name which will be passed to FastCGI as environment variable."),
+ AP_INIT_TAKE12("FCGIWrapper", set_wrapper_config, NULL,
+ RSRC_CONF | ACCESS_CONF | OR_FILEINFO,
+ "The CGI wrapper setting"),
+ AP_INIT_TAKE1("PHP_Fix_Pathinfo_Enable",
+ set_php_fix_pathinfo_enable,
+ NULL, RSRC_CONF,
+ "Set 1, if cgi.fix_pathinfo=1 in php.ini"),
+ AP_INIT_TAKE1("MaxRequestsPerProcess", set_max_requests_per_process,
+ NULL, RSRC_CONF,
+ "Max requests handled by each fastcgi application"),
+ AP_INIT_TAKE1("FastCgiAuthenticator", set_authenticator_info, NULL,
+ ACCESS_CONF | OR_FILEINFO,
+ "a absolute authenticator file path"),
+ AP_INIT_FLAG("FastCgiAuthenticatorAuthoritative",
+ set_authenticator_authoritative, NULL,
+ ACCESS_CONF | OR_FILEINFO,
+ "Set to 'off' to allow authentication to be passed along to lower modules upon failure"),
+ AP_INIT_TAKE1("FastCgiAuthorizer", set_authorizer_info, NULL,
+ ACCESS_CONF | OR_FILEINFO,
+ "a absolute authorizer file path"),
+ AP_INIT_FLAG("FastCgiAuthorizerAuthoritative",
+ set_authorizer_authoritative, NULL,
+ ACCESS_CONF | OR_FILEINFO,
+ "Set to 'off' to allow authorization to be passed along to lower modules upon failure"),
+ AP_INIT_TAKE1("FastCgiAccessChecker", set_access_info, NULL,
+ ACCESS_CONF | OR_FILEINFO,
+ "a absolute access checker file path"),
+ AP_INIT_FLAG("FastCgiAccessCheckerAuthoritative",
+ set_access_authoritative, NULL, ACCESS_CONF | OR_FILEINFO,
+ "Set to 'off' to allow access control to be passed along to lower modules upon failure"),
+ {NULL}
};
static void register_hooks(apr_pool_t * p)
{
- ap_hook_post_config(fcgid_init, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_child_init(initialize_child, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_handler(fcgid_handler, NULL, NULL, APR_HOOK_MIDDLE);
- ap_hook_check_user_id(mod_fcgid_authenticator, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_auth_checker(mod_fcgid_authorizer, NULL, NULL,
- APR_HOOK_MIDDLE);
- ap_hook_access_checker(mod_fcgid_check_access, NULL, NULL,
- APR_HOOK_MIDDLE);
+ ap_hook_post_config(fcgid_init, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_child_init(initialize_child, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_handler(fcgid_handler, NULL, NULL, APR_HOOK_MIDDLE);
+ ap_hook_check_user_id(mod_fcgid_authenticator, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ ap_hook_auth_checker(mod_fcgid_authorizer, NULL, NULL,
+ APR_HOOK_MIDDLE);
+ ap_hook_access_checker(mod_fcgid_check_access, NULL, NULL,
+ APR_HOOK_MIDDLE);
- /* Insert fcgid output filter */
- fcgid_filter_handle =
- ap_register_output_filter("FCGID_OUT",
- fcgid_filter,
- NULL, AP_FTYPE_RESOURCE - 10);
+ /* Insert fcgid output filter */
+ fcgid_filter_handle =
+ ap_register_output_filter("FCGID_OUT",
+ fcgid_filter,
+ NULL, AP_FTYPE_RESOURCE - 10);
}
module AP_MODULE_DECLARE_DATA fcgid_module = {
- STANDARD20_MODULE_STUFF,
- create_fcgid_dir_config, /* create per-directory config structure */
- NULL, /* merge per-directory config structures */
- create_fcgid_server_config, /* create per-server config structure */
- merge_fcgid_server_config, /* merge per-server config structures */
- fcgid_cmds, /* command apr_table_t */
- register_hooks /* register hooks */
+ STANDARD20_MODULE_STUFF,
+ create_fcgid_dir_config, /* create per-directory config structure */
+ NULL, /* merge per-directory config structures */
+ create_fcgid_server_config, /* create per-server config structure */
+ merge_fcgid_server_config, /* merge per-server config structures */
+ fcgid_cmds, /* command apr_table_t */
+ register_hooks /* register hooks */
};