#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
*/
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. */
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);
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()) {
#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"
}
}
+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
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);
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)
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,
{
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);
}
/*
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));
{
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;
/* 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) {
}
/* everything will be cleared shortly */
#endif
+ if (*shm) {
+ *shm = ap_scoreboard_shm;
+ }
return APR_SUCCESS;
}
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
{
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;
}