summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Bloom <rbb@apache.org>2002-01-30 22:35:57 +0000
committerRyan Bloom <rbb@apache.org>2002-01-30 22:35:57 +0000
commit5cd54703000e93e0ca3944b157767e3b4190b9a4 (patch)
tree82ed76b034d736bbebaa9e64948ca530d881394a
parent465e16b71ba8149a46c5b1ba52c5ccb21ee451ce (diff)
downloadhttpd-5cd54703000e93e0ca3944b157767e3b4190b9a4.tar.gz
Change the Windows MPM to only use the pre_mpm phase in the parent process.
The child processes use the child_init phase to reattach to the shared memory. This makes Windows work like Unix, which should make it easier for module authors to write portable modules. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@93119 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--include/scoreboard.h6
-rw-r--r--server/mpm/prefork/prefork.c2
-rw-r--r--server/mpm/winnt/mpm_winnt.c37
-rw-r--r--server/mpm/worker/worker.c2
-rw-r--r--server/scoreboard.c26
5 files changed, 43 insertions, 30 deletions
diff --git a/include/scoreboard.h b/include/scoreboard.h
index c8c67d7abc..a58dd72e7a 100644
--- a/include/scoreboard.h
+++ b/include/scoreboard.h
@@ -73,6 +73,7 @@ extern "C" {
#include "apr_hooks.h"
#include "apr_thread_proc.h"
#include "apr_portable.h"
+#include "apr_shm.h"
/* Scoreboard info on a process is, for now, kept very brief ---
* just status value and pid (the latter so that the caretaker process
@@ -113,8 +114,7 @@ typedef int ap_generation_t;
*/
typedef enum {
SB_NOT_SHARED = 1,
- SB_SHARED = 2, /* PARENT */
- SB_SHARED_CHILD = 3
+ SB_SHARED = 2
} ap_scoreboard_e;
#define SB_WORKING 0 /* The server is busy and the child is useful. */
@@ -185,7 +185,7 @@ AP_DECLARE(int) ap_exists_scoreboard_image(void);
AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r);
int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t);
-apr_status_t reopen_scoreboard(apr_pool_t *p, int detached);
+apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached);
void ap_init_scoreboard(void *shared_score);
int ap_calc_scoreboard_size(void);
apr_status_t ap_cleanup_scoreboard(void *d);
diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c
index cac1a3b37d..78c47a0e9a 100644
--- a/server/mpm/prefork/prefork.c
+++ b/server/mpm/prefork/prefork.c
@@ -594,7 +594,7 @@ static void child_main(int child_num_arg)
apr_pool_tag(ptrans, "transaction");
/* needs to be done before we switch UIDs so we have permissions */
- reopen_scoreboard(pchild, 0);
+ ap_reopen_scoreboard(pchild, NULL, 0);
SAFE_ACCEPT(accept_mutex_child_init(pchild));
if (unixd_setup_child()) {
diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c
index 040afa86a8..fbbf1dec98 100644
--- a/server/mpm/winnt/mpm_winnt.c
+++ b/server/mpm/winnt/mpm_winnt.c
@@ -67,6 +67,7 @@
#include "apr_getopt.h"
#include "apr_strings.h"
#include "apr_lib.h"
+#include "apr_shm.h"
#include "ap_mpm.h"
#include "ap_config.h"
#include "ap_listen.h"
@@ -281,6 +282,23 @@ static void CleanNullACL( void *sa ) {
}
}
+static void winnt_child_init(apr_pool_t *pchild, struct server_rec *ap_server_conf)
+{
+ void *sb_shared;
+ int rv;
+
+ rv = ap_reopen_scoreboard(pchild, &ap_scoreboard_shm, 1);
+ if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
+ ap_log_error(APLOG_MARK, APLOG_CRIT, 0, NULL, "Looks like we're gonna die %d %x", rv, ap_scoreboard_shm);
+ exit(APEXIT_INIT); /* XXX need to return an error from this function */
+ }
+ ap_init_scoreboard(sb_shared);
+
+ ap_scoreboard_image->parent[0].pid = parent_pid;
+ ap_scoreboard_image->parent[0].quiescing = 0;
+}
+
+
/*
* The Win32 call WaitForMultipleObjects will only allow you to wait for
* a maximum of MAXIMUM_WAIT_OBJECTS (current 64). Since the threading
@@ -994,7 +1012,14 @@ static void child_main()
exit_event = OpenEvent(EVENT_ALL_ACCESS, FALSE, exit_event_name);
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
"Child %d: exit_event_name = %s", my_pid, exit_event_name);
+ /* Set up the scoreboard. */
+ ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
+ ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
+ "getting listeners child_main", my_pid);
+ get_listeners_from_parent(ap_server_conf);
}
+ ap_log_error(APLOG_MARK, APLOG_CRIT, APR_SUCCESS, ap_server_conf,
+ "in child_main", my_pid);
/* Initialize the child_events */
max_requests_per_child_event = CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -2117,7 +2142,6 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
HANDLE sb_os_shm;
DWORD BytesRead;
apr_status_t rv;
-
pipe = GetStdHandle(STD_INPUT_HANDLE);
if (!ReadFile(pipe, &sb_os_shm, sizeof(sb_os_shm),
&BytesRead, (LPOVERLAPPED) NULL)
@@ -2135,18 +2159,14 @@ AP_DECLARE(int) ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s )
exit(1);
}
- if (ap_run_pre_mpm(pconf, SB_SHARED_CHILD) != OK) {
- exit(1);
- }
+
ap_my_generation = atoi(getenv("AP_MY_GENERATION"));
- get_listeners_from_parent(ap_server_conf);
}
- ap_scoreboard_image->parent[0].pid = parent_pid;
- ap_scoreboard_image->parent[0].quiescing = 0;
-
+
if (!set_listeners_noninheritable(pconf)) {
return 1;
}
+
child_main();
ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf,
@@ -2195,6 +2215,7 @@ static void winnt_hooks(apr_pool_t *p)
{
ap_hook_pre_config(winnt_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(winnt_post_config, NULL, NULL, 0);
+ ap_hook_child_init(winnt_child_init, NULL, NULL, APR_HOOK_MIDDLE);
}
/*
diff --git a/server/mpm/worker/worker.c b/server/mpm/worker/worker.c
index fe7cc4ad0e..d3f95dfdf3 100644
--- a/server/mpm/worker/worker.c
+++ b/server/mpm/worker/worker.c
@@ -874,7 +874,7 @@ static void child_main(int child_num_arg)
apr_pool_create(&pchild, pconf);
/*stuff to do before we switch id's, so we have permissions.*/
- reopen_scoreboard(pchild, 0);
+ ap_reopen_scoreboard(pchild, NULL, 0);
rv = SAFE_ACCEPT(apr_proc_mutex_child_init(&accept_mutex, ap_lock_fname,
pchild));
diff --git a/server/scoreboard.c b/server/scoreboard.c
index 23e4541517..81a2ed6e17 100644
--- a/server/scoreboard.c
+++ b/server/scoreboard.c
@@ -143,7 +143,8 @@ void ap_init_scoreboard(void *shared_score)
{
char *more_storage;
int i;
-
+
+ ap_calc_scoreboard_size();
ap_scoreboard_image =
calloc(1, sizeof(scoreboard) + server_limit * sizeof(worker_score *));
more_storage = shared_score;
@@ -200,7 +201,7 @@ static apr_status_t open_scoreboard(apr_pool_t *p)
/* If detach is non-zero, this is a seperate child process,
* if zero, it is a forked child.
*/
-apr_status_t reopen_scoreboard(apr_pool_t *p, int detached)
+apr_status_t ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached)
{
#if APR_HAS_SHARED_MEMORY
if (!detached) {
@@ -215,6 +216,9 @@ apr_status_t reopen_scoreboard(apr_pool_t *p, int detached)
}
/* everything will be cleared shortly */
#endif
+ if (*shm) {
+ *shm = ap_scoreboard_shm;
+ }
return APR_SUCCESS;
}
@@ -260,14 +264,6 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
memset(sb_shared, 0, scoreboard_size);
ap_init_scoreboard(sb_shared);
}
- else if (sb_type == SB_SHARED_CHILD) {
- void *sb_shared;
- rv = reopen_scoreboard(p, 1);
- if (rv || !(sb_shared = apr_shm_baseaddr_get(ap_scoreboard_shm))) {
- return HTTP_INTERNAL_SERVER_ERROR;
- }
- ap_init_scoreboard(sb_shared);
- }
else
#endif
{
@@ -282,14 +278,10 @@ int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e sb_type)
ap_init_scoreboard(sb_mem);
}
}
- /* can't just memset() */
- if (sb_type != SB_SHARED_CHILD) {
- ap_scoreboard_image->global->sb_type = sb_type;
- ap_scoreboard_image->global->running_generation = running_gen;
- apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard,
- apr_pool_cleanup_null);
- }
+ ap_scoreboard_image->global->sb_type = sb_type;
+ ap_scoreboard_image->global->running_generation = running_gen;
ap_restart_time = apr_time_now();
+ apr_pool_cleanup_register(p, NULL, ap_cleanup_scoreboard, apr_pool_cleanup_null);
return OK;
}