1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
60 #include "apr_strings.h"
61 #include "apr_getopt.h"
62 #include "apr_general.h"
65 #define APR_WANT_STDIO
69 #include "ap_config.h"
71 #include "http_main.h"
73 #include "http_config.h"
74 #include "http_vhost.h"
76 #include "util_ebcdic.h"
79 /* WARNING: Win32 binds http_main.c dynamically to the server. Please place
80 * extern functions and global data in another appropriate module.
82 * Most significant main() global data can be found in http_config.c
85 /* XXX - We should be able to grab the per-MPM settings here too */
86 static void show_compile_settings(void)
88 printf("Server version: %s\n", ap_get_server_version());
89 printf("Server built: %s\n", ap_get_server_built());
90 printf("Server's Module Magic Number: %u:%u\n",
91 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
92 printf("Server compiled with....\n");
93 #ifdef BIG_SECURITY_HOLE
94 printf(" -D BIG_SECURITY_HOLE\n");
96 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
97 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
100 printf(" -D APACHE_MPM_DIR=\"%s\"\n", APACHE_MPM_DIR);
103 printf(" -D HAVE_SHMGET\n");
105 #ifdef AP_USE_FILE_BASED_SCOREBOARD
106 printf(" -D AP_USE_FILE_BASED_SCOREBOARD\n");
108 #ifdef AP_USE_MEM_BASED_SCOREBOARD
109 printf(" -D AP_USE_MEM_BASED_SCOREBOARD\n");
112 printf(" -D APR_HAS_MMAP\n");
113 #endif /*APR_HAS_MMAP*/
115 printf(" -D NO_WRITEV\n");
118 printf(" -D NO_LINGCLOSE\n");
121 printf(" -D APR_HAVE_IPV6\n");
123 #if APR_USE_FLOCK_SERIALIZE
124 printf(" -D APR_USE_FLOCK_SERIALIZE\n");
126 #if APR_USE_SYSVSEM_SERIALIZE
127 printf(" -D APR_USE_SYSVSEM_SERIALIZE\n");
129 #if APR_USE_FCNTL_SERIALIZE
130 printf(" -D APR_USE_FCNTL_SERIALIZE\n");
132 #if APR_USE_PROC_PTHREAD_SERIALIZE
133 printf(" -D APR_USE_PROC_PTHREAD_SERIALIZE\n");
135 #if APR_USE_PTHREAD_SERIALIZE
136 printf(" -D APR_USE_PTHREAD_SERIALIZE\n");
138 #if APR_PROCESS_LOCK_IS_GLOBAL
139 printf(" -D APR_PROCESS_LOCK_IS_GLOBAL\n");
141 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
142 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
144 #if APR_HAS_OTHER_CHILD
145 printf(" -D APR_HAS_OTHER_CHILD\n");
147 #ifdef AP_HAVE_RELIABLE_PIPED_LOGS
148 printf(" -D AP_HAVE_RELIABLE_PIPED_LOGS\n");
151 printf(" -D BUFFERED_LOGS\n");
153 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
156 #if APR_CHARSET_EBCDIC
157 printf(" -D APR_CHARSET_EBCDIC\n");
160 printf(" -D APACHE_XLATE\n");
162 #ifdef NEED_HASHBANG_EMUL
163 printf(" -D NEED_HASHBANG_EMUL\n");
166 printf(" -D SHARED_CORE\n");
169 /* This list displays the compiled in default paths: */
171 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
174 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
176 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
177 printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
179 #ifdef DEFAULT_PIDLOG
180 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
182 #ifdef DEFAULT_SCOREBOARD
183 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
185 #ifdef DEFAULT_LOCKFILE
186 printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
188 #ifdef DEFAULT_ERRORLOG
189 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
191 #ifdef TYPES_CONFIG_FILE
192 printf(" -D TYPES_CONFIG_FILE=\"" TYPES_CONFIG_FILE "\"\n");
194 #ifdef SERVER_CONFIG_FILE
195 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
199 static void destroy_and_exit_process(process_rec *process, int process_exit_value)
201 apr_pool_destroy(process->pool); /* and destroy all descendent pools */
203 exit(process_exit_value);
206 static process_rec *create_process(int argc, const char * const *argv)
208 process_rec *process;
212 stat = apr_pool_create(&cntx, NULL);
213 if (stat != APR_SUCCESS) {
214 /* XXX From the time that we took away the NULL pool->malloc mapping
215 * we have been unable to log here without segfaulting.
217 ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
218 "apr_pool_create() failed to create "
224 ap_open_stderr_log(cntx);
226 process = apr_palloc(cntx, sizeof(process_rec));
227 process->pool = cntx;
229 apr_pool_create(&process->pconf, process->pool);
230 process->argc = argc;
231 process->argv = argv;
232 process->short_name = apr_filename_of_pathname(argv[0]);
236 static void usage(process_rec *process)
238 const char *bin = process->argv[0];
239 char pad[MAX_STRING_LEN];
242 for (i = 0; i < strlen(bin); i++)
246 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,NULL , "Usage: %s [-R directory] [-D name] [-d directory] [-f file]", bin);
248 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage: %s [-D name] [-d directory] [-f file]", bin);
250 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-C \"directive\"] [-c \"directive\"]", pad);
252 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-k restart|shutdown|start]", pad);
253 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-n service_name]", pad);
254 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-i] [-u]", pad);
256 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-v] [-V] [-h] [-l] [-L] [-t] [-T]", pad);
257 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Options:");
259 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -R directory : specify an alternate location for shared object files");
261 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -D name : define a name for use in <IfDefine name> directives");
262 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -d directory : specify an alternate initial ServerRoot");
263 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f file : specify an alternate ServerConfigFile");
264 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C \"directive\" : process directive before reading config files");
265 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c \"directive\" : process directive after reading config files");
267 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -n name : set service name and use its ServerConfigFile");
268 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k shutdown : tell running Apache to shutdown");
269 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k restart : tell running Apache to do a graceful restart");
270 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k start : tell Apache to start");
271 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -i : install an Apache service");
272 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -u : uninstall an Apache service");
274 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v : show version number");
275 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V : show compile settings");
276 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h : list available command line options (this page)");
277 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -l : list compiled in modules");
278 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -L : list available configuration directives");
279 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings)");
280 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t : run syntax check for config files (with docroot check)");
281 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -T : run syntax check for config files (without docroot check)");
282 /* TODOC: -X goes away, expect MPMs to use -D options */
283 destroy_and_exit_process(process, 1);
286 int main(int argc, const char * const argv[])
289 int configtestonly = 0;
290 const char *confname = SERVER_CONFIG_FILE;
291 const char *def_server_root = HTTPD_ROOT;
292 process_rec *process;
293 server_rec *server_conf;
296 apr_pool_t *plog; /* Pool of log streams, reset _after_ each read of conf */
297 apr_pool_t *ptemp; /* Pool for temporary config stuff, reset often */
298 apr_pool_t *pcommands; /* Pool for -D, -C and -c switches */
305 process = create_process(argc, argv);
306 pglobal = process->pool;
307 pconf = process->pconf;
308 ap_server_argv0 = process->short_name;
310 #if APR_CHARSET_EBCDIC
311 if (ap_init_ebcdic(pglobal) != APR_SUCCESS) {
312 destroy_and_exit_process(process, 1);
318 ap_setup_prelinked_modules(process);
320 apr_pool_create(&pcommands, pglobal);
321 ap_server_pre_read_config = apr_array_make(pcommands, 1, sizeof(char *));
322 ap_server_post_read_config = apr_array_make(pcommands, 1, sizeof(char *));
323 ap_server_config_defines = apr_array_make(pcommands, 1, sizeof(char *));
325 ap_run_rewrite_args(process);
327 /* Maintain AP_SERVER_BASEARGS list in http_main.h to allow the MPM
328 * to safely pass on our args from its rewrite_args() handler.
330 apr_getopt_init(&opt, pcommands, process->argc, process->argv);
332 while (apr_getopt(opt, AP_SERVER_BASEARGS, &c, &optarg)
337 new = (char **)apr_array_push(ap_server_post_read_config);
338 *new = apr_pstrdup(pcommands, optarg);
341 new = (char **)apr_array_push(ap_server_pre_read_config);
342 *new = apr_pstrdup(pcommands, optarg);
345 def_server_root = optarg;
348 new = (char **)apr_array_push(ap_server_config_defines);
349 *new = apr_pstrdup(pcommands, optarg);
355 printf("Server version: %s\n", ap_get_server_version());
356 printf("Server built: %s\n", ap_get_server_built());
357 destroy_and_exit_process(process, 0);
359 show_compile_settings();
360 destroy_and_exit_process(process, 0);
363 destroy_and_exit_process(process, 0);
365 ap_show_directives();
366 destroy_and_exit_process(process, 0);
376 apr_pool_create(&plog, pglobal);
377 apr_pool_create(&ptemp, pconf);
379 /* Note that we preflight the config file once
380 before reading it _again_ in the main loop.
381 This allows things, log files configuration
382 for example, to settle down. */
384 ap_server_root = def_server_root;
385 server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
386 ap_run_pre_config(pconf, plog, ptemp);
387 ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
388 ap_fixup_virtual_hosts(pconf, server_conf);
389 ap_fini_vhost_config(pconf, server_conf);
391 if (configtestonly) {
392 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
393 destroy_and_exit_process(process, 0);
395 apr_pool_clear(plog);
396 ap_run_open_logs(pconf, plog, ptemp, server_conf);
397 ap_post_config_hook(pconf, plog, ptemp, server_conf);
398 apr_pool_destroy(ptemp);
401 apr_hook_deregister_all();
402 apr_pool_clear(pconf);
403 for (mod = ap_prelinked_modules; *mod != NULL; mod++) {
404 ap_register_hooks(*mod, pconf);
408 /* This is a hack until we finish the code so that it only reads
409 * the config file once and just operates on the tree already in
413 apr_pool_create(&ptemp, pconf);
414 ap_server_root = def_server_root;
415 server_conf = ap_read_config(process, ptemp, confname, &ap_conftree);
416 ap_run_pre_config(pconf, plog, ptemp);
417 ap_process_config_tree(server_conf, ap_conftree, process->pconf, ptemp);
418 ap_fixup_virtual_hosts(pconf, server_conf);
419 ap_fini_vhost_config(pconf, server_conf);
421 apr_pool_clear(plog);
422 ap_run_open_logs(pconf, plog, ptemp, server_conf);
423 ap_post_config_hook(pconf, plog, ptemp, server_conf);
424 apr_pool_destroy(ptemp);
426 ap_run_optional_fn_retrieve();
428 if (ap_mpm_run(pconf, plog, server_conf)) break;
430 destroy_and_exit_process(process, 0);
431 return 0; /* Supress compiler warning. */
434 /* force Expat to be linked into the server executable */
435 #if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP)
436 #include "xmlparse.h"
437 const XML_LChar *suck_in_expat(void);
438 const XML_LChar *suck_in_expat(void)
440 return XML_ErrorString(XML_ERROR_NONE);
442 #endif /* USE_EXPAT */
444 #ifndef SHARED_CORE_BOOTSTRAP
446 * Force apr_password_validate() into the image so that modules like
447 * mod_auth can use it even if they're dynamically loaded.
449 void suck_in_apr_password_validate(void);
450 void suck_in_apr_password_validate(void)
452 apr_password_validate("a", "b");
456 #ifdef AP_USING_AUTOCONF
457 /* This ugly little hack pulls any function referenced in exports.c into
458 * the web server. exports.c is generated during the build, and it
459 * has all of the APR functions specified by the apr/apr.exports and
460 * apr-util/aprutil.exports files.
462 const void *suck_in_APR(void);
463 const void *suck_in_APR(void)
465 extern const void *ap_ugly_hack;