mirror of
https://github.com/apache/httpd.git
synced 2025-11-06 16:49:32 +03:00
Well this was thought provoking.
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
This commit is contained in:
@@ -71,7 +71,7 @@ struct ap_listen_rec {
|
|||||||
ap_listen_rec *ap_listeners;
|
ap_listen_rec *ap_listeners;
|
||||||
|
|
||||||
void ap_listen_pre_config(void);
|
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_listenbacklog(cmd_parms *cmd, void *dummy, char *arg);
|
||||||
const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips);
|
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);
|
const char *ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, char *arg);
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ void ap_single_module_configure(ap_context_t *p, server_rec *s, module *m);
|
|||||||
|
|
||||||
/* For http_main.c... */
|
/* 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_directives(void);
|
||||||
void ap_show_modules(void);
|
void ap_show_modules(void);
|
||||||
server_rec *ap_read_config(process_rec *process, ap_context_t *temp_pool, const char *config_name);
|
server_rec *ap_read_config(process_rec *process, ap_context_t *temp_pool, const char *config_name);
|
||||||
|
|||||||
@@ -526,7 +526,7 @@ API_EXPORT(void) ap_remove_loaded_module(module *mod)
|
|||||||
*m = NULL;
|
*m = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ap_setup_prelinked_modules()
|
void ap_setup_prelinked_modules(process_rec *process)
|
||||||
{
|
{
|
||||||
module **m;
|
module **m;
|
||||||
module **m2;
|
module **m2;
|
||||||
@@ -541,7 +541,7 @@ void ap_setup_prelinked_modules()
|
|||||||
/*
|
/*
|
||||||
* Initialise list of loaded modules
|
* 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));
|
sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
|
||||||
if (ap_loaded_modules == NULL) {
|
if (ap_loaded_modules == NULL) {
|
||||||
fprintf(stderr, "Ouch! Out of memory in ap_setup_prelinked_modules()!\n");
|
fprintf(stderr, "Ouch! Out of memory in ap_setup_prelinked_modules()!\n");
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ static ap_status_t close_listeners_on_exec(void *v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 **walk;
|
||||||
ap_listen_rec *new;
|
ap_listen_rec *new;
|
||||||
@@ -174,7 +174,7 @@ static void alloc_listener(char *addr, unsigned int port)
|
|||||||
|
|
||||||
/* this has to survive restarts */
|
/* this has to survive restarts */
|
||||||
/* XXX - We need to deal with freeing this structure properly. */
|
/* 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;
|
new->active = 0;
|
||||||
if (ap_create_tcp_socket(&new->sd, NULL) != APR_SUCCESS) {
|
if (ap_create_tcp_socket(&new->sd, NULL) != APR_SUCCESS) {
|
||||||
ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
|
ap_log_error(APLOG_MARK, APLOG_CRIT, NULL,
|
||||||
@@ -188,15 +188,16 @@ static void alloc_listener(char *addr, unsigned int port)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 *lr;
|
||||||
ap_listen_rec *next;
|
ap_listen_rec *next;
|
||||||
int num_open;
|
int num_open;
|
||||||
|
|
||||||
/* allocate a default listener if necessary */
|
/* allocate a default listener if necessary */
|
||||||
if (ap_listeners == NULL) {
|
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;
|
num_open = 0;
|
||||||
@@ -265,11 +266,11 @@ const char *ap_set_listener(cmd_parms *cmd, void *dummy, char *ips)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ports == ips) { /* no address */
|
if (ports == ips) { /* no address */
|
||||||
alloc_listener(APR_ANYADDR, port);
|
alloc_listener(cmd->server->process, APR_ANYADDR, port);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ips[(ports - ips) - 1] = '\0';
|
ips[(ports - ips) - 1] = '\0';
|
||||||
alloc_listener(ips, port);
|
alloc_listener(cmd->server->process, ips, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@@ -293,13 +293,13 @@ API_EXPORT_NONSTD(int) main(int argc, char *argv[])
|
|||||||
|
|
||||||
g_pHookPool=pglobal;
|
g_pHookPool=pglobal;
|
||||||
|
|
||||||
|
ap_setup_prelinked_modules(process);
|
||||||
|
|
||||||
ap_create_context(&pcommands, pglobal);
|
ap_create_context(&pcommands, pglobal);
|
||||||
ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *));
|
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_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
|
||||||
ap_server_config_defines = 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) {
|
while ((c = getopt(argc, argv, "C:c:d:f:vVlLth")) != -1) {
|
||||||
char **new;
|
char **new;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ static int setup_listeners(ap_context_t *p, server_rec *s)
|
|||||||
ap_listen_rec *lr;
|
ap_listen_rec *lr;
|
||||||
int num_listeners = 0;
|
int num_listeners = 0;
|
||||||
|
|
||||||
if (ap_listen_open(p, s->port)) {
|
if (ap_listen_open(s->process, s->port)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (lr = ap_listeners; lr; lr = lr->next) {
|
for (lr = ap_listeners; lr; lr = lr->next) {
|
||||||
@@ -1293,7 +1293,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
server_conf = s;
|
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? */
|
/* 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,
|
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
|
||||||
"no listening sockets available, shutting down");
|
"no listening sockets available, shutting down");
|
||||||
|
|||||||
@@ -674,11 +674,11 @@ static void process_child_status(int pid, ap_wait_t status)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setup_listeners(ap_context_t *pconf, server_rec *s)
|
static int setup_listeners(server_rec *s)
|
||||||
{
|
{
|
||||||
ap_listen_rec *lr;
|
ap_listen_rec *lr;
|
||||||
int num_listeners = 0;
|
int num_listeners = 0;
|
||||||
if (ap_listen_open(pconf, s->port)) {
|
if (ap_listen_open(s->process, s->port)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (lr = ap_listeners; lr; lr = lr->next) {
|
for (lr = ap_listeners; lr; lr = lr->next) {
|
||||||
@@ -1303,7 +1303,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
server_conf = s;
|
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? */
|
/* 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,
|
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
|
||||||
"no listening sockets available, shutting down");
|
"no listening sockets available, shutting down");
|
||||||
|
|||||||
@@ -2535,7 +2535,7 @@ static int setup_listeners(ap_context_t *p, server_rec *s)
|
|||||||
ap_listen_rec *lr;
|
ap_listen_rec *lr;
|
||||||
int sockdes;
|
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,
|
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
|
||||||
"no listening sockets available, shutting down");
|
"no listening sockets available, shutting down");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -1378,11 +1378,11 @@ static void process_child_status(int tid, ap_wait_t status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int setup_listeners(ap_context_t *pconf, server_rec *s)
|
static int setup_listeners(server_rec *s)
|
||||||
{
|
{
|
||||||
ap_listen_rec *lr;
|
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,
|
ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s,
|
||||||
"no listening sockets available, shutting down");
|
"no listening sockets available, shutting down");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -1413,7 +1413,7 @@ int ap_mpm_run(ap_context_t *_pconf, ap_context_t *plog, server_rec *s)
|
|||||||
server_conf = s;
|
server_conf = s;
|
||||||
ap_log_pid(pconf, ap_pid_fname);
|
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? */
|
/* XXX: hey, what's the right way for the mpm to indicate a fatal error? */
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ static ap_inline ap_listen_rec *find_ready_listener(fd_set * main_fds)
|
|||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
static int setup_listeners(ap_context_t *pconf, server_rec *s)
|
static int setup_listeners(server_rec *s)
|
||||||
{
|
{
|
||||||
ap_listen_rec *lr;
|
ap_listen_rec *lr;
|
||||||
int num_listeners = 0;
|
int num_listeners = 0;
|
||||||
@@ -372,7 +372,7 @@ static int setup_listeners(ap_context_t *pconf, server_rec *s)
|
|||||||
/* Setup the listeners */
|
/* Setup the listeners */
|
||||||
FD_ZERO(&listenfds);
|
FD_ZERO(&listenfds);
|
||||||
|
|
||||||
if (ap_listen_open(pconf, s->port)) {
|
if (ap_listen_open(s->process, s->port)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
for (lr = ap_listeners; lr; lr = lr->next) {
|
for (lr = ap_listeners; lr; lr = lr->next) {
|
||||||
@@ -1028,7 +1028,7 @@ static void worker_main()
|
|||||||
|
|
||||||
/* start_mutex obtained, continue into the select() loop */
|
/* start_mutex obtained, continue into the select() loop */
|
||||||
if (one_process) {
|
if (one_process) {
|
||||||
setup_listeners(pconf, server_conf);
|
setup_listeners(server_conf);
|
||||||
} else {
|
} else {
|
||||||
/* Get listeners from the parent process */
|
/* Get listeners from the parent process */
|
||||||
setup_inherited_listeners(pconf, server_conf);
|
setup_inherited_listeners(pconf, server_conf);
|
||||||
@@ -1343,7 +1343,7 @@ static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_even
|
|||||||
HANDLE process_handles[MAX_PROCESSES];
|
HANDLE process_handles[MAX_PROCESSES];
|
||||||
HANDLE process_kill_events[MAX_PROCESSES];
|
HANDLE process_kill_events[MAX_PROCESSES];
|
||||||
|
|
||||||
setup_listeners(pconf, s);
|
setup_listeners(s);
|
||||||
|
|
||||||
/* Create child process
|
/* Create child process
|
||||||
* Should only be one in this version of Apache for WIN32
|
* Should only be one in this version of Apache for WIN32
|
||||||
|
|||||||
Reference in New Issue
Block a user