Drive out the use of malloc in two places.
In listen.c, using the global process pool instead. That changes the
API into listen so that a process is passed in rather than the config
pool. That's all was easy.
The pain is propogating a change into all N of the mpm, they
are all similar but different in their use of listen.c There
is a lot to dislike about similar but code scattered code.
I changed the N setup_listener routines, they now take only
the server since they can dig the config and global pool
out of there.
Free today: ap_setup_prelinked_modules now takes the process so it
can allocate it's table in the process's pool rathern than use
malloc.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@83943
13f79535-47bb-0310-9956-
ffa450edef68
ap_listen_rec *ap_listeners;
void ap_listen_pre_config(void);
-int ap_listen_open(ap_context_t *pconf, unsigned port);
+int ap_listen_open(process_rec *process, unsigned port);
const char *ap_set_listenbacklog(cmd_parms *cmd, void *dummy, char *arg);
const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips);
const char *ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg);
/* For http_main.c... */
-void ap_setup_prelinked_modules(void);
+void ap_setup_prelinked_modules(process_rec *process);
void ap_show_directives(void);
void ap_show_modules(void);
server_rec *ap_read_config(process_rec *process, ap_context_t *temp_pool, const char *config_name);
*m = NULL;
}
-void ap_setup_prelinked_modules()
+void ap_setup_prelinked_modules(process_rec *process)
{
module **m;
module **m2;
/*
* Initialise list of loaded modules
*/
- ap_loaded_modules = (module **)malloc(
+ ap_loaded_modules = (module **)ap_palloc(process->pool,
sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
if (ap_loaded_modules == NULL) {
fprintf(stderr, "Ouch! Out of memory in ap_setup_prelinked_modules()!\n");
}
-static void alloc_listener(char *addr, unsigned int port)
+static void alloc_listener(process_rec *process, char *addr, unsigned int port)
{
ap_listen_rec **walk;
ap_listen_rec *new;
/* this has to survive restarts */
/* XXX - We need to deal with freeing this structure properly. */
- new = malloc(sizeof(ap_listen_rec));
+ new = ap_palloc(process->pool, sizeof(ap_listen_rec));
new->active = 0;
if (ap_create_tcp_socket(&new->sd, NULL) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
}
-int ap_listen_open(ap_context_t *pconf, unsigned port)
+int ap_listen_open(process_rec *process, unsigned port)
{
+ ap_context_t *pconf = process->pconf;
ap_listen_rec *lr;
ap_listen_rec *next;
int num_open;
/* allocate a default listener if necessary */
if (ap_listeners == NULL) {
- alloc_listener(APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT);
+ alloc_listener(process, APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT);
}
num_open = 0;
}
if (ports == ips) { /* no address */
- alloc_listener(APR_ANYADDR, port);
+ alloc_listener(cmd->server->process, APR_ANYADDR, port);
}
else {
ips[(ports - ips) - 1] = '\0';
- alloc_listener(ips, port);
+ alloc_listener(cmd->server->process, ips, port);
}
return NULL;
g_pHookPool=pglobal;
+ ap_setup_prelinked_modules(process);
+
ap_create_context(&pcommands, pglobal);
ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *));
ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
- ap_setup_prelinked_modules();
-
while ((c = getopt(argc, argv, "C:c:d:f:vVlLth")) != -1) {
char **new;
switch (c) {
ap_listen_rec *lr;
int num_listeners = 0;
- if (ap_listen_open(p, s->port)) {
+ if (ap_listen_open(s->process, s->port)) {
return 0;
}
for (lr = ap_listeners; lr; lr = lr->next) {
exit(1);
}
server_conf = s;
- if ((num_listenfds = setup_listeners(pconf, server_conf)) < 1) {
+ if ((num_listenfds = setup_listeners(server_conf)) < 1) {
/* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
"no listening sockets available, shutting down");
}
}
-static int setup_listeners(ap_context_t *pconf, server_rec *s)
+static int setup_listeners(server_rec *s)
{
ap_listen_rec *lr;
int num_listeners = 0;
- if (ap_listen_open(pconf, s->port)) {
+ if (ap_listen_open(s->process, s->port)) {
return 0;
}
for (lr = ap_listeners; lr; lr = lr->next) {
exit(1);
}
server_conf = s;
- if ((num_listenfds = setup_listeners(pconf, server_conf)) < 1) {
+ if ((num_listenfds = setup_listeners(server_conf)) < 1) {
/* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
"no listening sockets available, shutting down");
ap_listen_rec *lr;
int sockdes;
- if (ap_listen_open(p, s->port)) {
+ if (ap_listen_open(s->process, s->port)) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
"no listening sockets available, shutting down");
return -1;
}
-static int setup_listeners(ap_context_t *pconf, server_rec *s)
+static int setup_listeners(server_rec *s)
{
ap_listen_rec *lr;
- if (ap_listen_open(pconf, s->port)) {
+ if (ap_listen_open(s->process, s->port)) {
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
"no listening sockets available, shutting down");
return -1;
server_conf = s;
ap_log_pid(pconf, ap_pid_fname);
- if (setup_listeners(pconf, s)) {
+ if (setup_listeners(s)) {
/* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
return 1;
}
}
return NULL;
}
-static int setup_listeners(ap_context_t *pconf, server_rec *s)
+static int setup_listeners(server_rec *s)
{
ap_listen_rec *lr;
int num_listeners = 0;
/* Setup the listeners */
FD_ZERO(&listenfds);
- if (ap_listen_open(pconf, s->port)) {
+ if (ap_listen_open(s->process, s->port)) {
return 0;
}
for (lr = ap_listeners; lr; lr = lr->next) {
/* start_mutex obtained, continue into the select() loop */
if (one_process) {
- setup_listeners(pconf, server_conf);
+ setup_listeners(server_conf);
} else {
/* Get listeners from the parent process */
setup_inherited_listeners(pconf, server_conf);
HANDLE process_handles[MAX_PROCESSES];
HANDLE process_kill_events[MAX_PROCESSES];
- setup_listeners(pconf, s);
+ setup_listeners(s);
/* Create child process
* Should only be one in this version of Apache for WIN32