You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ch...@apache.org on 2009/03/18 17:37:32 UTC

svn commit: r755634 [2/6] - in /httpd/mod_fcgid/trunk/mod_fcgid: ./ arch/unix/ arch/win32/

Modified: httpd/mod_fcgid/trunk/mod_fcgid/arch/unix/fcgid_proctbl_unix.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/arch/unix/fcgid_proctbl_unix.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/arch/unix/fcgid_proctbl_unix.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/arch/unix/fcgid_proctbl_unix.c Wed Mar 18 16:37:31 2009
@@ -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;
-	}
-
-	/* 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);
-
-	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);
+    /* 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;
+    }
+
+    apr_file_close(file);
+
+    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);
 
   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;
-
-	fname = get_shmpath(main_server);
-
-	/* 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 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;
-
-	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++;
-	}
+    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);
+
+    /* 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 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;
+
+    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++;
+    }
 
-	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);
-	}
-
-	/* 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);
-	}
+    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);
+    }
 }
 
 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++;
-
-	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_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_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);
+
+    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_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);
+    }
 }

Modified: httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_pm_win.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_pm_win.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_pm_win.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_pm_win.c Wed Mar 18 16:37:31 2009
@@ -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;
-
-		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;
+    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));
+        }
+
+        /* 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 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 */
-
-	/* 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 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);
+    }
+
+    /* 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 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;
-
-	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';
-		}
-	}
-
-	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;
-	}
+    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));
+
+    /* 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;
+
+    /* 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;
-
-		/* 
-		   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;
-		}
-
-		/* 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,
-							   &notifybyte)) != 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);
-		}
-	}
+    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));
+
+        /* 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;
+
+            if ((rv =
+                 apr_queue_pop(g_notifyqueue,
+                               &notifybyte)) != 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);
+        }
+    }
 
-	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);
-
-				return APR_SUCCESS;
-			}
-		}
-	}
+    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_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);
-
-	/* 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);
-		}
-	}
+    /* 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;
+
+        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;
 }

Modified: httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proc_win.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proc_win.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proc_win.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proc_win.c Wed Mar 18 16:37:31 2009
@@ -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;
-
-	/* 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));
-
-	/* 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);
-
-	/* 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));
-
-	/* 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';
-
-	/* 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)))
+    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;
+
+    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;
+    }
+
+    /* 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);
+
+    /* 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 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;
+    }
+
+    /* 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;
-	}
-
-	/* 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);
-
-	/* 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);
-	}
+    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;
+        }
+    }
+
+    /* 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);
+
+        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;
-
-	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);
-
-		/* Destroy pool */
-		apr_pool_destroy(procnode->proc_pool);
-		procnode->proc_pool = NULL;
-	}
+    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);
+
+        /* Register the death */
+        register_termination(main_server, procnode);
+
+        /* 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;
-
-	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;
-
-	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;
-
-	/* 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) {
-		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;
-	}
+    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;
+
+    /* 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);
+
+    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 */ );
+
+    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;
+    }
 
-	/* 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;
-
-	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 (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;
-		}
-	}
+    apr_status_t rv;
+    fcgid_namedpipe_handle *handle_info;
+    DWORD bytesread;
+
+    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 (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;
+        }
+    }
 }
 
 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;
-
-	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;
-
-		if (APR_BUCKET_IS_EOS(bucket_request))
-			break;
-
-		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;
-		}
-
-		/* 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;
-				}
-			}
-		}
-	}
+    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;
+
+    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_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;
+        }
+
+        /* 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;
+                }
+            }
+        }
+    }
 
-	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];
-
-	/* 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";
-	}
-
-	/* 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);
+    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);
+
+    /* 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);
 }

Modified: httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proctbl_win.c
URL: http://svn.apache.org/viewvc/httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proctbl_win.c?rev=755634&r1=755633&r2=755634&view=diff
==============================================================================
--- httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proctbl_win.c (original)
+++ httpd/mod_fcgid/trunk/mod_fcgid/arch/win32/fcgid_proctbl_win.c Wed Mar 18 16:37:31 2009
@@ -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;
-
-	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);
-	}
-
-	g_proc_array = _global_memory->procnode_array;
-	g_global_share = &_global_memory->global;
-
-	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++;
-	}
+    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);
+    }
+
+    /* 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_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++;
+    }
 
-	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++;
-
-	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_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_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);
+
+    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_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);
+    }
 }