~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to server/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
 
2
 * contributor license agreements.  See the NOTICE file distributed with
 
3
 * this work for additional information regarding copyright ownership.
 
4
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
5
 * (the "License"); you may not use this file except in compliance with
 
6
 * the License.  You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include "apr.h"
 
18
#include "apr_strings.h"
 
19
#include "apr_getopt.h"
 
20
#include "apr_general.h"
 
21
#include "apr_lib.h"
 
22
#include "apr_md5.h"
 
23
#include "apr_version.h"
 
24
#include "apu_version.h"
 
25
 
 
26
#define APR_WANT_STDIO
 
27
#define APR_WANT_STRFUNC
 
28
#include "apr_want.h"
 
29
 
 
30
#define CORE_PRIVATE
 
31
#include "ap_config.h"
 
32
#include "httpd.h"
 
33
#include "http_main.h"
 
34
#include "http_log.h"
 
35
#include "http_config.h"
 
36
#include "http_core.h"
 
37
#include "http_vhost.h"
 
38
#include "apr_uri.h"
 
39
#include "util_ebcdic.h"
 
40
#include "ap_mpm.h"
 
41
#include "mpm_common.h"
 
42
 
 
43
/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
 
44
 *          extern functions and global data in another appropriate module.
 
45
 *
 
46
 * Most significant main() global data can be found in http_config.c
 
47
 */
 
48
 
 
49
static void show_mpm_settings(void)
 
50
{
 
51
    int mpm_query_info;
 
52
    apr_status_t retval;
 
53
 
 
54
    printf("Server MPM:     %s\n", ap_show_mpm());
 
55
 
 
56
    retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
 
57
 
 
58
    if (retval == APR_SUCCESS) {
 
59
        printf("  threaded:     ");
 
60
 
 
61
        if (mpm_query_info == AP_MPMQ_DYNAMIC) {
 
62
            printf("yes (variable thread count)\n");
 
63
        }
 
64
        else if (mpm_query_info == AP_MPMQ_STATIC) {
 
65
            printf("yes (fixed thread count)\n");
 
66
        }
 
67
        else {
 
68
            printf("no\n");
 
69
        }
 
70
    }
 
71
 
 
72
    retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
 
73
 
 
74
    if (retval == APR_SUCCESS) {
 
75
        printf("    forked:     ");
 
76
 
 
77
        if (mpm_query_info == AP_MPMQ_DYNAMIC) {
 
78
            printf("yes (variable process count)\n");
 
79
        }
 
80
        else if (mpm_query_info == AP_MPMQ_STATIC) {
 
81
            printf("yes (fixed process count)\n");
 
82
        }
 
83
        else {
 
84
            printf("no\n");
 
85
        }
 
86
    }
 
87
}
 
88
 
 
89
static void show_compile_settings(void)
 
90
{
 
91
    printf("Server version: %s\n", ap_get_server_version());
 
92
    printf("Server built:   %s\n", ap_get_server_built());
 
93
    printf("Server's Module Magic Number: %u:%u\n",
 
94
           MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
 
95
    printf("Server loaded:  APR %s, APR-Util %s\n",
 
96
           apr_version_string(), apu_version_string());
 
97
    printf("Compiled using: APR %s, APR-Util %s\n",
 
98
           APR_VERSION_STRING, APU_VERSION_STRING);
 
99
    /* sizeof(foo) is long on some platforms so we might as well
 
100
     * make it long everywhere to keep the printf format
 
101
     * consistent
 
102
     */
 
103
    printf("Architecture:   %ld-bit\n", 8 * (long)sizeof(void *));
 
104
 
 
105
    show_mpm_settings();
 
106
 
 
107
    printf("Server compiled with....\n");
 
108
#ifdef BIG_SECURITY_HOLE
 
109
    printf(" -D BIG_SECURITY_HOLE\n");
 
110
#endif
 
111
 
 
112
#ifdef SECURITY_HOLE_PASS_AUTHORIZATION
 
113
    printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
 
114
#endif
 
115
 
 
116
#ifdef OS
 
117
    printf(" -D OS=\"" OS "\"\n");
 
118
#endif
 
119
 
 
120
#ifdef APACHE_MPM_DIR
 
121
    printf(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n");
 
122
#endif
 
123
 
 
124
#ifdef HAVE_SHMGET
 
125
    printf(" -D HAVE_SHMGET\n");
 
126
#endif
 
127
 
 
128
#if APR_FILE_BASED_SHM
 
129
    printf(" -D APR_FILE_BASED_SHM\n");
 
130
#endif
 
131
 
 
132
#if APR_HAS_SENDFILE
 
133
    printf(" -D APR_HAS_SENDFILE\n");
 
134
#endif
 
135
 
 
136
#if APR_HAS_MMAP
 
137
    printf(" -D APR_HAS_MMAP\n");
 
138
#endif
 
139
 
 
140
#ifdef NO_WRITEV
 
141
    printf(" -D NO_WRITEV\n");
 
142
#endif
 
143
 
 
144
#ifdef NO_LINGCLOSE
 
145
    printf(" -D NO_LINGCLOSE\n");
 
146
#endif
 
147
 
 
148
#if APR_HAVE_IPV6
 
149
    printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
 
150
#ifdef AP_ENABLE_V4_MAPPED
 
151
    printf("enabled)\n");
 
152
#else
 
153
    printf("disabled)\n");
 
154
#endif
 
155
#endif
 
156
 
 
157
#if APR_USE_FLOCK_SERIALIZE
 
158
    printf(" -D APR_USE_FLOCK_SERIALIZE\n");
 
159
#endif
 
160
 
 
161
#if APR_USE_SYSVSEM_SERIALIZE
 
162
    printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
 
163
#endif
 
164
 
 
165
#if APR_USE_POSIXSEM_SERIALIZE
 
166
    printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
 
167
#endif
 
168
 
 
169
#if APR_USE_FCNTL_SERIALIZE
 
170
    printf(" -D APR_USE_FCNTL_SERIALIZE\n");
 
171
#endif
 
172
 
 
173
#if APR_USE_PROC_PTHREAD_SERIALIZE
 
174
    printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
 
175
#endif
 
176
 
 
177
#if APR_USE_PTHREAD_SERIALIZE
 
178
    printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
 
179
#endif
 
180
 
 
181
#if APR_PROCESS_LOCK_IS_GLOBAL
 
182
    printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
 
183
#endif
 
184
 
 
185
#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 
186
    printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
 
187
#endif
 
188
 
 
189
#if APR_HAS_OTHER_CHILD
 
190
    printf(" -D APR_HAS_OTHER_CHILD\n");
 
191
#endif
 
192
 
 
193
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
 
194
    printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
 
195
#endif
 
196
 
 
197
#ifdef BUFFERED_LOGS
 
198
    printf(" -D BUFFERED_LOGS\n");
 
199
#ifdef PIPE_BUF
 
200
    printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
 
201
#endif
 
202
#endif
 
203
 
 
204
    printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
 
205
 
 
206
#if APR_CHARSET_EBCDIC
 
207
    printf(" -D APR_CHARSET_EBCDIC\n");
 
208
#endif
 
209
 
 
210
#ifdef NEED_HASHBANG_EMUL
 
211
    printf(" -D NEED_HASHBANG_EMUL\n");
 
212
#endif
 
213
 
 
214
#ifdef SHARED_CORE
 
215
    printf(" -D SHARED_CORE\n");
 
216
#endif
 
217
 
 
218
/* This list displays the compiled in default paths: */
 
219
#ifdef HTTPD_ROOT
 
220
    printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
 
221
#endif
 
222
 
 
223
#ifdef SUEXEC_BIN
 
224
    printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
 
225
#endif
 
226
 
 
227
#if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
 
228
    printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
 
229
#endif
 
230
 
 
231
#ifdef DEFAULT_PIDLOG
 
232
    printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
 
233
#endif
 
234
 
 
235
#ifdef DEFAULT_SCOREBOARD
 
236
    printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
 
237
#endif
 
238
 
 
239
#ifdef DEFAULT_LOCKFILE
 
240
    printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
 
241
#endif
 
242
 
 
243
#ifdef DEFAULT_ERRORLOG
 
244
    printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
 
245
#endif
 
246
 
 
247
#ifdef AP_TYPES_CONFIG_FILE
 
248
    printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
 
249
#endif
 
250
 
 
251
#ifdef SERVER_CONFIG_FILE
 
252
    printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
 
253
#endif
 
254
}
 
255
 
 
256
static void destroy_and_exit_process(process_rec *process,
 
257
                                     int process_exit_value)
 
258
{
 
259
    apr_pool_destroy(process->pool); /* and destroy all descendent pools */
 
260
    apr_terminate();
 
261
    exit(process_exit_value);
 
262
}
 
263
 
 
264
static process_rec *create_process(int argc, const char * const *argv)
 
265
{
 
266
    process_rec *process;
 
267
    apr_pool_t *cntx;
 
268
    apr_status_t stat;
 
269
 
 
270
    stat = apr_pool_create(&cntx, NULL);
 
271
    if (stat != APR_SUCCESS) {
 
272
        /* XXX From the time that we took away the NULL pool->malloc mapping
 
273
         *     we have been unable to log here without segfaulting.
 
274
         */
 
275
        ap_log_error(APLOG_MARK, APLOG_ERR, stat, NULL,
 
276
                     "apr_pool_create() failed to create "
 
277
                     "initial context");
 
278
        apr_terminate();
 
279
        exit(1);
 
280
    }
 
281
 
 
282
    apr_pool_tag(cntx, "process");
 
283
    ap_open_stderr_log(cntx);
 
284
 
 
285
    process = apr_palloc(cntx, sizeof(process_rec));
 
286
    process->pool = cntx;
 
287
 
 
288
    apr_pool_create(&process->pconf, process->pool);
 
289
    apr_pool_tag(process->pconf, "pconf");
 
290
    process->argc = argc;
 
291
    process->argv = argv;
 
292
    process->short_name = apr_filepath_name_get(argv[0]);
 
293
    return process;
 
294
}
 
295
 
 
296
static void usage(process_rec *process)
 
297
{
 
298
    const char *bin = process->argv[0];
 
299
    char pad[MAX_STRING_LEN];
 
300
    unsigned i;
 
301
 
 
302
    for (i = 0; i < strlen(bin); i++) {
 
303
        pad[i] = ' ';
 
304
    }
 
305
 
 
306
    pad[i] = '\0';
 
307
 
 
308
#ifdef SHARED_CORE
 
309
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL ,
 
310
                 "Usage: %s [-R directory] [-D name] [-d directory] [-f file]",
 
311
                 bin);
 
312
#else
 
313
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
314
                 "Usage: %s [-D name] [-d directory] [-f file]", bin);
 
315
#endif
 
316
 
 
317
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
318
                 "       %s [-C \"directive\"] [-c \"directive\"]", pad);
 
319
 
 
320
#ifdef WIN32
 
321
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
322
                 "       %s [-w] [-k start|restart|stop|shutdown]", pad);
 
323
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
324
                 "       %s [-k install|config|uninstall] [-n service_name]",
 
325
                 pad);
 
326
#endif
 
327
#ifdef AP_MPM_WANT_SIGNAL_SERVER
 
328
#ifdef AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN
 
329
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
330
                 "       %s [-k start|restart|graceful|graceful-stop|stop]",
 
331
                 pad);
 
332
#else
 
333
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
334
                 "       %s [-k start|restart|graceful|stop]",
 
335
                 pad);
 
336
#endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */
 
337
#endif
 
338
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
339
                 "       %s [-v] [-V] [-h] [-l] [-L] [-t] [-S]", pad);
 
340
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
341
                 "Options:");
 
342
 
 
343
#ifdef SHARED_CORE
 
344
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
345
                 "  -R directory       : specify an alternate location for "
 
346
                 "shared object files");
 
347
#endif
 
348
 
 
349
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
350
                 "  -D name            : define a name for use in "
 
351
                 "<IfDefine name> directives");
 
352
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
353
                 "  -d directory       : specify an alternate initial "
 
354
                 "ServerRoot");
 
355
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
356
                 "  -f file            : specify an alternate ServerConfigFile");
 
357
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
358
                 "  -C \"directive\"     : process directive before reading "
 
359
                 "config files");
 
360
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
361
                 "  -c \"directive\"     : process directive after reading "
 
362
                 "config files");
 
363
 
 
364
#ifdef NETWARE
 
365
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
366
                 "  -n name            : set screen name");
 
367
#endif
 
368
#ifdef WIN32
 
369
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
370
                 "  -n name            : set service name and use its "
 
371
                 "ServerConfigFile");
 
372
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
373
                 "  -k start           : tell Apache to start");
 
374
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
375
                 "  -k restart         : tell running Apache to do a graceful "
 
376
                 "restart");
 
377
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
378
                 "  -k stop|shutdown   : tell running Apache to shutdown");
 
379
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
380
                 "  -k install         : install an Apache service");
 
381
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
382
                 "  -k config          : change startup Options of an Apache "
 
383
                 "service");
 
384
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
385
                 "  -k uninstall       : uninstall an Apache service");
 
386
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
387
                 "  -w                 : hold open the console window on error");
 
388
#endif
 
389
 
 
390
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
391
                 "  -e level           : show startup errors of level "
 
392
                 "(see LogLevel)");
 
393
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
394
                 "  -E file            : log startup errors to file");
 
395
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
396
                 "  -v                 : show version number");
 
397
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
398
                 "  -V                 : show compile settings");
 
399
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
400
                 "  -h                 : list available command line options "
 
401
                 "(this page)");
 
402
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
403
                 "  -l                 : list compiled in modules");
 
404
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
405
                 "  -L                 : list available configuration "
 
406
                 "directives");
 
407
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
408
                 "  -t -D DUMP_VHOSTS  : show parsed settings (currently only "
 
409
                 "vhost settings)");
 
410
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
411
                 "  -S                 : a synonym for -t -D DUMP_VHOSTS");
 
412
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
413
                 "  -t -D DUMP_MODULES : show all loaded modules ");
 
414
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
415
                 "  -M                 : a synonym for -t -D DUMP_MODULES");
 
416
    ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
 
417
                 "  -t                 : run syntax check for config files");
 
418
 
 
419
    destroy_and_exit_process(process, 1);
 
420
}
 
421
 
 
422
int main(int argc, const char * const argv[])
 
423
{
 
424
    char c;
 
425
    int configtestonly = 0;
 
426
    const char *confname = SERVER_CONFIG_FILE;
 
427
    const char *def_server_root = HTTPD_ROOT;
 
428
    const char *temp_error_log = NULL;
 
429
    const char *error;
 
430
    process_rec *process;
 
431
    server_rec *server_conf;
 
432
    apr_pool_t *pglobal;
 
433
    apr_pool_t *pconf;
 
434
    apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
 
435
    apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
 
436
    apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
 
437
    apr_getopt_t *opt;
 
438
    apr_status_t rv;
 
439
    module **mod;
 
440
    const char *optarg;
 
441
    APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
 
442
 
 
443
    AP_MONCONTROL(0); /* turn off profiling of startup */
 
444
 
 
445
    apr_app_initialize(&argc, &argv, NULL);
 
446
 
 
447
    process = create_process(argc, argv);
 
448
    pglobal = process->pool;
 
449
    pconf = process->pconf;
 
450
    ap_server_argv0 = process->short_name;
 
451
 
 
452
#if APR_CHARSET_EBCDIC
 
453
    if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
 
454
        destroy_and_exit_process(process, 1);
 
455
    }
 
456
#endif
 
457
 
 
458
    apr_pool_create(&pcommands, pglobal);
 
459
    apr_pool_tag(pcommands, "pcommands");
 
460
    ap_server_pre_read_config  = apr_array_make(pcommands, 1, sizeof(char *));
 
461
    ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
 
462
    ap_server_config_defines   = apr_array_make(pcommands, 1, sizeof(char *));
 
463
 
 
464
    error = ap_setup_prelinked_modules(process);
 
465
    if (error) {
 
466
        ap_log_error(APLOG_MARK, APLOG_STARTUP|APLOG_EMERG, 0, NULL, "%s: %s",
 
467
                     ap_server_argv0, error);
 
468
        destroy_and_exit_process(process, 1);
 
469
    }
 
470
 
 
471
    ap_run_rewrite_args(process);
 
472
 
 
473
    /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
 
474
     * to safely pass on our args from its rewrite_args() handler.
 
475
     */
 
476
    apr_getopt_init(&opt, pcommands, process->argc, process->argv);
 
477
 
 
478
    while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg))
 
479
            == APR_SUCCESS) {
 
480
        char **new;
 
481
 
 
482
        switch (c) {
 
483
        case 'c':
 
484
            new = (char **)apr_array_push(ap_server_post_read_config);
 
485
            *new = apr_pstrdup(pcommands, optarg);
 
486
            break;
 
487
 
 
488
        case 'C':
 
489
            new = (char **)apr_array_push(ap_server_pre_read_config);
 
490
            *new = apr_pstrdup(pcommands, optarg);
 
491
            break;
 
492
 
 
493
        case 'd':
 
494
            def_server_root = optarg;
 
495
            break;
 
496
 
 
497
        case 'D':
 
498
            new = (char **)apr_array_push(ap_server_config_defines);
 
499
            *new = apr_pstrdup(pcommands, optarg);
 
500
            /* Setting -D DUMP_VHOSTS is equivalent to setting -S */
 
501
            if (strcmp(optarg, "DUMP_VHOSTS") == 0)
 
502
                configtestonly = 1;
 
503
            /* Setting -D DUMP_MODULES is equivalent to setting -M */
 
504
            if (strcmp(optarg, "DUMP_MODULES") == 0)
 
505
                configtestonly = 1;
 
506
            break;
 
507
 
 
508
        case 'e':
 
509
            if (strcasecmp(optarg, "emerg") == 0) {
 
510
                ap_default_loglevel = APLOG_EMERG;
 
511
            }
 
512
            else if (strcasecmp(optarg, "alert") == 0) {
 
513
                ap_default_loglevel = APLOG_ALERT;
 
514
            }
 
515
            else if (strcasecmp(optarg, "crit") == 0) {
 
516
                ap_default_loglevel = APLOG_CRIT;
 
517
            }
 
518
            else if (strncasecmp(optarg, "err", 3) == 0) {
 
519
                ap_default_loglevel = APLOG_ERR;
 
520
            }
 
521
            else if (strncasecmp(optarg, "warn", 4) == 0) {
 
522
                ap_default_loglevel = APLOG_WARNING;
 
523
            }
 
524
            else if (strcasecmp(optarg, "notice") == 0) {
 
525
                ap_default_loglevel = APLOG_NOTICE;
 
526
            }
 
527
            else if (strcasecmp(optarg, "info") == 0) {
 
528
                ap_default_loglevel = APLOG_INFO;
 
529
            }
 
530
            else if (strcasecmp(optarg, "debug") == 0) {
 
531
                ap_default_loglevel = APLOG_DEBUG;
 
532
            }
 
533
            else {
 
534
                usage(process);
 
535
            }
 
536
            break;
 
537
 
 
538
        case 'E':
 
539
            temp_error_log = apr_pstrdup(process->pool, optarg);
 
540
            break;
 
541
 
 
542
        case 'X':
 
543
            new = (char **)apr_array_push(ap_server_config_defines);
 
544
            *new = "DEBUG";
 
545
            break;
 
546
 
 
547
        case 'f':
 
548
            confname = optarg;
 
549
            break;
 
550
 
 
551
        case 'v':
 
552
            printf("Server version: %s\n", ap_get_server_version());
 
553
            printf("Server built:   %s\n", ap_get_server_built());
 
554
            destroy_and_exit_process(process, 0);
 
555
 
 
556
        case 'V':
 
557
            show_compile_settings();
 
558
            destroy_and_exit_process(process, 0);
 
559
 
 
560
        case 'l':
 
561
            ap_show_modules();
 
562
            destroy_and_exit_process(process, 0);
 
563
 
 
564
        case 'L':
 
565
            ap_show_directives();
 
566
            destroy_and_exit_process(process, 0);
 
567
 
 
568
        case 't':
 
569
            configtestonly = 1;
 
570
            break;
 
571
 
 
572
        case 'S':
 
573
            configtestonly = 1;
 
574
            new = (char **)apr_array_push(ap_server_config_defines);
 
575
            *new = "DUMP_VHOSTS";
 
576
            break;
 
577
 
 
578
        case 'M':
 
579
            configtestonly = 1;
 
580
            new = (char **)apr_array_push(ap_server_config_defines);
 
581
            *new = "DUMP_MODULES";
 
582
            break;
 
583
 
 
584
        case 'h':
 
585
        case '?':
 
586
            usage(process);
 
587
        }
 
588
    }
 
589
 
 
590
    /* bad cmdline option?  then we die */
 
591
    if (rv != APR_EOF || opt->ind < opt->argc) {
 
592
        usage(process);
 
593
    }
 
594
 
 
595
    apr_pool_create(&plog, pglobal);
 
596
    apr_pool_tag(plog, "plog");
 
597
    apr_pool_create(&ptemp, pconf);
 
598
    apr_pool_tag(ptemp, "ptemp");
 
599
 
 
600
    /* Note that we preflight the config file once
 
601
     * before reading it _again_ in the main loop.
 
602
     * This allows things, log files configuration
 
603
     * for example, to settle down.
 
604
     */
 
605
 
 
606
    ap_server_root = def_server_root;
 
607
    if (temp_error_log) {
 
608
        ap_replace_stderr_log(process->pool, temp_error_log);
 
609
    }
 
610
    server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
 
611
    if (!server_conf) {
 
612
        destroy_and_exit_process(process, 1);
 
613
    }
 
614
 
 
615
    if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
 
616
        ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
 
617
                     NULL, "Pre-configuration failed");
 
618
        destroy_and_exit_process(process, 1);
 
619
    }
 
620
 
 
621
    rv = ap_process_config_tree(server_conf, ap_conftree,
 
622
                                process->pconf, ptemp);
 
623
    if (rv == OK) {
 
624
        ap_fixup_virtual_hosts(pconf, server_conf);
 
625
        ap_fini_vhost_config(pconf, server_conf);
 
626
        apr_hook_sort_all();
 
627
 
 
628
        if (configtestonly) {
 
629
            ap_run_test_config(pconf, server_conf);
 
630
            ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "Syntax OK");
 
631
            destroy_and_exit_process(process, 0);
 
632
        }
 
633
    }
 
634
 
 
635
    signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
 
636
    if (signal_server) {
 
637
        int exit_status;
 
638
 
 
639
        if (signal_server(&exit_status, pconf) != 0) {
 
640
            destroy_and_exit_process(process, exit_status);
 
641
        }
 
642
    }
 
643
 
 
644
    /* If our config failed, deal with that here. */
 
645
    if (rv != OK) {
 
646
        destroy_and_exit_process(process, 1);
 
647
    }
 
648
 
 
649
    apr_pool_clear(plog);
 
650
 
 
651
    if ( ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
 
652
        ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
 
653
                     0, NULL, "Unable to open logs");
 
654
        destroy_and_exit_process(process, 1);
 
655
    }
 
656
 
 
657
    if ( ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
 
658
        ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR, 0,
 
659
                     NULL, "Configuration Failed");
 
660
        destroy_and_exit_process(process, 1);
 
661
    }
 
662
 
 
663
    apr_pool_destroy(ptemp);
 
664
 
 
665
    for (;;) {
 
666
        apr_hook_deregister_all();
 
667
        apr_pool_clear(pconf);
 
668
 
 
669
        for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
 
670
            ap_register_hooks(*mod, pconf);
 
671
        }
 
672
 
 
673
        /* This is a hack until we finish the code so that it only reads
 
674
         * the config file once and just operates on the tree already in
 
675
         * memory.  rbb
 
676
         */
 
677
        ap_conftree = NULL;
 
678
        apr_pool_create(&ptemp, pconf);
 
679
        apr_pool_tag(ptemp, "ptemp");
 
680
        ap_server_root = def_server_root;
 
681
        server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
 
682
        if (!server_conf) {
 
683
            destroy_and_exit_process(process, 1);
 
684
        }
 
685
 
 
686
        if (ap_run_pre_config(pconf, plog, ptemp) != OK) {
 
687
            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
 
688
                         0, NULL, "Pre-configuration failed");
 
689
            destroy_and_exit_process(process, 1);
 
690
        }
 
691
 
 
692
        if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
 
693
                                   ptemp) != OK) {
 
694
            destroy_and_exit_process(process, 1);
 
695
        }
 
696
        ap_fixup_virtual_hosts(pconf, server_conf);
 
697
        ap_fini_vhost_config(pconf, server_conf);
 
698
        apr_hook_sort_all();
 
699
        apr_pool_clear(plog);
 
700
        if (ap_run_open_logs(pconf, plog, ptemp, server_conf) != OK) {
 
701
            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
 
702
                         0, NULL, "Unable to open logs");
 
703
            destroy_and_exit_process(process, 1);
 
704
        }
 
705
 
 
706
        if (ap_run_post_config(pconf, plog, ptemp, server_conf) != OK) {
 
707
            ap_log_error(APLOG_MARK, APLOG_STARTUP |APLOG_ERR,
 
708
                         0, NULL, "Configuration Failed");
 
709
            destroy_and_exit_process(process, 1);
 
710
        }
 
711
 
 
712
        apr_pool_destroy(ptemp);
 
713
        apr_pool_lock(pconf, 1);
 
714
 
 
715
        ap_run_optional_fn_retrieve();
 
716
 
 
717
        if (ap_mpm_run(pconf, plog, server_conf))
 
718
            break;
 
719
 
 
720
        apr_pool_lock(pconf, 0);
 
721
    }
 
722
 
 
723
    apr_pool_lock(pconf, 0);
 
724
    destroy_and_exit_process(process, 0);
 
725
 
 
726
    return 0; /* Termination 'ok' */
 
727
}
 
728
 
 
729
#ifdef AP_USING_AUTOCONF
 
730
/* This ugly little hack pulls any function referenced in exports.c into
 
731
 * the web server.  exports.c is generated during the build, and it
 
732
 * has all of the APR functions specified by the apr/apr.exports and
 
733
 * apr-util/aprutil.exports files.
 
734
 */
 
735
const void *suck_in_APR(void);
 
736
const void *suck_in_APR(void)
 
737
{
 
738
    extern const void *ap_ugly_hack;
 
739
 
 
740
    return ap_ugly_hack;
 
741
}
 
742
#endif