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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
#include "apr_strings.h"
19
#include "apr_getopt.h"
20
#include "apr_general.h"
23
#include "apr_version.h"
24
#include "apu_version.h"
26
#define APR_WANT_STDIO
27
#define APR_WANT_STRFUNC
31
#include "ap_config.h"
33
#include "http_main.h"
35
#include "http_config.h"
36
#include "http_core.h"
37
#include "http_vhost.h"
39
#include "util_ebcdic.h"
41
#include "mpm_common.h"
43
/* WARNING: Win32 binds http_main.c dynamically to the server. Please place
44
* extern functions and global data in another appropriate module.
46
* Most significant main() global data can be found in http_config.c
49
static void show_mpm_settings(void)
54
printf("Server MPM: %s\n", ap_show_mpm());
56
retval = ap_mpm_query(AP_MPMQ_IS_THREADED, &mpm_query_info);
58
if (retval == APR_SUCCESS) {
59
printf(" threaded: ");
61
if (mpm_query_info == AP_MPMQ_DYNAMIC) {
62
printf("yes (variable thread count)\n");
64
else if (mpm_query_info == AP_MPMQ_STATIC) {
65
printf("yes (fixed thread count)\n");
72
retval = ap_mpm_query(AP_MPMQ_IS_FORKED, &mpm_query_info);
74
if (retval == APR_SUCCESS) {
77
if (mpm_query_info == AP_MPMQ_DYNAMIC) {
78
printf("yes (variable process count)\n");
80
else if (mpm_query_info == AP_MPMQ_STATIC) {
81
printf("yes (fixed process count)\n");
89
static void show_compile_settings(void)
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
103
printf("Architecture: %ld-bit\n", 8 * (long)sizeof(void *));
107
printf("Server compiled with....\n");
108
#ifdef BIG_SECURITY_HOLE
109
printf(" -D BIG_SECURITY_HOLE\n");
112
#ifdef SECURITY_HOLE_PASS_AUTHORIZATION
113
printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
117
printf(" -D OS=\"" OS "\"\n");
120
#ifdef APACHE_MPM_DIR
121
printf(" -D APACHE_MPM_DIR=\"" APACHE_MPM_DIR "\"\n");
125
printf(" -D HAVE_SHMGET\n");
128
#if APR_FILE_BASED_SHM
129
printf(" -D APR_FILE_BASED_SHM\n");
133
printf(" -D APR_HAS_SENDFILE\n");
137
printf(" -D APR_HAS_MMAP\n");
141
printf(" -D NO_WRITEV\n");
145
printf(" -D NO_LINGCLOSE\n");
149
printf(" -D APR_HAVE_IPV6 (IPv4-mapped addresses ");
150
#ifdef AP_ENABLE_V4_MAPPED
151
printf("enabled)\n");
153
printf("disabled)\n");
157
#if APR_USE_FLOCK_SERIALIZE
158
printf(" -D APR_USE_FLOCK_SERIALIZE\n");
161
#if APR_USE_SYSVSEM_SERIALIZE
162
printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
165
#if APR_USE_POSIXSEM_SERIALIZE
166
printf(" -D APR_USE_POSIXSEM_SERIALIZE\n");
169
#if APR_USE_FCNTL_SERIALIZE
170
printf(" -D APR_USE_FCNTL_SERIALIZE\n");
173
#if APR_USE_PROC_PTHREAD_SERIALIZE
174
printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
177
#if APR_USE_PTHREAD_SERIALIZE
178
printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
181
#if APR_PROCESS_LOCK_IS_GLOBAL
182
printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
185
#ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
186
printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
189
#if APR_HAS_OTHER_CHILD
190
printf(" -D APR_HAS_OTHER_CHILD\n");
193
#ifdef AP_HAVE_RELIABLE_PIPED_LOGS
194
printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
198
printf(" -D BUFFERED_LOGS\n");
200
printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
204
printf(" -D DYNAMIC_MODULE_LIMIT=%ld\n",(long)DYNAMIC_MODULE_LIMIT);
206
#if APR_CHARSET_EBCDIC
207
printf(" -D APR_CHARSET_EBCDIC\n");
210
#ifdef NEED_HASHBANG_EMUL
211
printf(" -D NEED_HASHBANG_EMUL\n");
215
printf(" -D SHARED_CORE\n");
218
/* This list displays the compiled in default paths: */
220
printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
224
printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
227
#if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
228
printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
231
#ifdef DEFAULT_PIDLOG
232
printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
235
#ifdef DEFAULT_SCOREBOARD
236
printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
239
#ifdef DEFAULT_LOCKFILE
240
printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
243
#ifdef DEFAULT_ERRORLOG
244
printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
247
#ifdef AP_TYPES_CONFIG_FILE
248
printf(" -D AP_TYPES_CONFIG_FILE=\"" AP_TYPES_CONFIG_FILE "\"\n");
251
#ifdef SERVER_CONFIG_FILE
252
printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
256
static void destroy_and_exit_process(process_rec *process,
257
int process_exit_value)
259
apr_pool_destroy(process->pool); /* and destroy all descendent pools */
261
exit(process_exit_value);
264
static process_rec *create_process(int argc, const char * const *argv)
266
process_rec *process;
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.
275
ap_log_error(APLOG_MARK, APLOG_ERR, stat, NULL,
276
"apr_pool_create() failed to create "
282
apr_pool_tag(cntx, "process");
283
ap_open_stderr_log(cntx);
285
process = apr_palloc(cntx, sizeof(process_rec));
286
process->pool = cntx;
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]);
296
static void usage(process_rec *process)
298
const char *bin = process->argv[0];
299
char pad[MAX_STRING_LEN];
302
for (i = 0; i < strlen(bin); i++) {
309
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL ,
310
"Usage: %s [-R directory] [-D name] [-d directory] [-f file]",
313
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
314
"Usage: %s [-D name] [-d directory] [-f file]", bin);
317
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
318
" %s [-C \"directive\"] [-c \"directive\"]", pad);
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]",
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]",
333
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
334
" %s [-k start|restart|graceful|stop]",
336
#endif /* AP_MPM_WANT_SET_GRACEFUL_SHUTDOWN */
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,
344
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
345
" -R directory : specify an alternate location for "
346
"shared object files");
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 "
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 "
360
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
361
" -c \"directive\" : process directive after reading "
365
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
366
" -n name : set screen name");
369
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
370
" -n name : set service name and use its "
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 "
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 "
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");
390
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
391
" -e level : show startup errors of level "
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 "
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 "
407
ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL,
408
" -t -D DUMP_VHOSTS : show parsed settings (currently only "
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");
419
destroy_and_exit_process(process, 1);
422
int main(int argc, const char * const argv[])
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;
430
process_rec *process;
431
server_rec *server_conf;
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 */
441
APR_OPTIONAL_FN_TYPE(ap_signal_server) *signal_server;
443
AP_MONCONTROL(0); /* turn off profiling of startup */
445
apr_app_initialize(&argc, &argv, NULL);
447
process = create_process(argc, argv);
448
pglobal = process->pool;
449
pconf = process->pconf;
450
ap_server_argv0 = process->short_name;
452
#if APR_CHARSET_EBCDIC
453
if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
454
destroy_and_exit_process(process, 1);
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 *));
464
error = ap_setup_prelinked_modules(process);
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);
471
ap_run_rewrite_args(process);
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.
476
apr_getopt_init(&opt, pcommands, process->argc, process->argv);
478
while ((rv = apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg))
484
new = (char **)apr_array_push(ap_server_post_read_config);
485
*new = apr_pstrdup(pcommands, optarg);
489
new = (char **)apr_array_push(ap_server_pre_read_config);
490
*new = apr_pstrdup(pcommands, optarg);
494
def_server_root = optarg;
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)
503
/* Setting -D DUMP_MODULES is equivalent to setting -M */
504
if (strcmp(optarg, "DUMP_MODULES") == 0)
509
if (strcasecmp(optarg, "emerg") == 0) {
510
ap_default_loglevel = APLOG_EMERG;
512
else if (strcasecmp(optarg, "alert") == 0) {
513
ap_default_loglevel = APLOG_ALERT;
515
else if (strcasecmp(optarg, "crit") == 0) {
516
ap_default_loglevel = APLOG_CRIT;
518
else if (strncasecmp(optarg, "err", 3) == 0) {
519
ap_default_loglevel = APLOG_ERR;
521
else if (strncasecmp(optarg, "warn", 4) == 0) {
522
ap_default_loglevel = APLOG_WARNING;
524
else if (strcasecmp(optarg, "notice") == 0) {
525
ap_default_loglevel = APLOG_NOTICE;
527
else if (strcasecmp(optarg, "info") == 0) {
528
ap_default_loglevel = APLOG_INFO;
530
else if (strcasecmp(optarg, "debug") == 0) {
531
ap_default_loglevel = APLOG_DEBUG;
539
temp_error_log = apr_pstrdup(process->pool, optarg);
543
new = (char **)apr_array_push(ap_server_config_defines);
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);
557
show_compile_settings();
558
destroy_and_exit_process(process, 0);
562
destroy_and_exit_process(process, 0);
565
ap_show_directives();
566
destroy_and_exit_process(process, 0);
574
new = (char **)apr_array_push(ap_server_config_defines);
575
*new = "DUMP_VHOSTS";
580
new = (char **)apr_array_push(ap_server_config_defines);
581
*new = "DUMP_MODULES";
590
/* bad cmdline option? then we die */
591
if (rv != APR_EOF || opt->ind < opt->argc) {
595
apr_pool_create(&plog, pglobal);
596
apr_pool_tag(plog, "plog");
597
apr_pool_create(&ptemp, pconf);
598
apr_pool_tag(ptemp, "ptemp");
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.
606
ap_server_root = def_server_root;
607
if (temp_error_log) {
608
ap_replace_stderr_log(process->pool, temp_error_log);
610
server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
612
destroy_and_exit_process(process, 1);
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);
621
rv = ap_process_config_tree(server_conf, ap_conftree,
622
process->pconf, ptemp);
624
ap_fixup_virtual_hosts(pconf, server_conf);
625
ap_fini_vhost_config(pconf, server_conf);
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);
635
signal_server = APR_RETRIEVE_OPTIONAL_FN(ap_signal_server);
639
if (signal_server(&exit_status, pconf) != 0) {
640
destroy_and_exit_process(process, exit_status);
644
/* If our config failed, deal with that here. */
646
destroy_and_exit_process(process, 1);
649
apr_pool_clear(plog);
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);
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);
663
apr_pool_destroy(ptemp);
666
apr_hook_deregister_all();
667
apr_pool_clear(pconf);
669
for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
670
ap_register_hooks(*mod, pconf);
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
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);
683
destroy_and_exit_process(process, 1);
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);
692
if (ap_process_config_tree(server_conf, ap_conftree, process->pconf,
694
destroy_and_exit_process(process, 1);
696
ap_fixup_virtual_hosts(pconf, server_conf);
697
ap_fini_vhost_config(pconf, server_conf);
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);
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);
712
apr_pool_destroy(ptemp);
713
apr_pool_lock(pconf, 1);
715
ap_run_optional_fn_retrieve();
717
if (ap_mpm_run(pconf, plog, server_conf))
720
apr_pool_lock(pconf, 0);
723
apr_pool_lock(pconf, 0);
724
destroy_and_exit_process(process, 0);
726
return 0; /* Termination 'ok' */
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.
735
const void *suck_in_APR(void);
736
const void *suck_in_APR(void)
738
extern const void *ap_ugly_hack;