1 /* ====================================================================
2 * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the Apache Group
19 * for use in the Apache HTTP server project (http://www.apache.org/)."
21 * 4. The names "Apache Server" and "Apache Group" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
26 * 5. Products derived from this software may not be called "Apache"
27 * nor may "Apache" appear in their names without prior written
28 * permission of the Apache Group.
30 * 6. Redistributions of any form whatsoever must retain the following
32 * "This product includes software developed by the Apache Group
33 * for use in the Apache HTTP server project (http://www.apache.org/)."
35 * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Group and was originally based
51 * on public domain software written at the National Center for
52 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
53 * For more information on the Apache Group and the Apache HTTP server
54 * project, please see <http://www.apache.org/>.
59 #include "ap_config.h"
61 #include "http_main.h"
63 #include "http_config.h"
65 #include "apr_getopt.h"
68 const char *ap_server_argv0;
70 const char *ap_server_root;
72 ap_array_header_t *ap_server_pre_read_config;
73 ap_array_header_t *ap_server_post_read_config;
74 ap_array_header_t *ap_server_config_defines;
76 /* XXX - We should be able to grab the per-MPM settings here too */
77 static void show_compile_settings(void)
79 printf("Server version: %s\n", ap_get_server_version());
80 printf("Server built: %s\n", ap_get_server_built());
81 printf("Server's Module Magic Number: %u:%u\n",
82 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
83 printf("Server compiled with....\n");
84 #ifdef BIG_SECURITY_HOLE
85 printf(" -D BIG_SECURITY_HOLE\n");
87 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
88 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
91 printf(" -D HAVE_MMAP\n");
94 printf(" -D HAVE_SHMGET\n");
96 #ifdef USE_MMAP_SCOREBOARD
97 printf(" -D USE_MMAP_SCOREBOARD\n");
99 #ifdef USE_SHMGET_SCOREBOARD
100 printf(" -D USE_SHMGET_SCOREBOARD\n");
102 #ifdef USE_OS2_SCOREBOARD
103 printf(" -D USE_OS2_SCOREBOARD\n");
105 #ifdef USE_POSIX_SCOREBOARD
106 printf(" -D USE_POSIX_SCOREBOARD\n");
108 #ifdef USE_MMAP_FILES
109 printf(" -D USE_MMAP_FILES\n");
110 #ifdef MMAP_SEGMENT_SIZE
111 printf(" -D MMAP_SEGMENT_SIZE=%ld\n",(long)MMAP_SEGMENT_SIZE);
113 #endif /*USE_MMAP_FILES*/
115 printf(" -D NO_WRITEV\n");
118 printf(" -D NO_LINGCLOSE\n");
120 #ifdef USE_FCNTL_SERIALIZED_ACCEPT
121 printf(" -D USE_FCNTL_SERIALIZED_ACCEPT\n");
123 #ifdef USE_FLOCK_SERIALIZED_ACCEPT
124 printf(" -D USE_FLOCK_SERIALIZED_ACCEPT\n");
126 #ifdef USE_USLOCK_SERIALIZED_ACCEPT
127 printf(" -D USE_USLOCK_SERIALIZED_ACCEPT\n");
129 #ifdef USE_SYSVSEM_SERIALIZED_ACCEPT
130 printf(" -D USE_SYSVSEM_SERIALIZED_ACCEPT\n");
132 #ifdef USE_PTHREAD_SERIALIZED_ACCEPT
133 printf(" -D USE_PTHREAD_SERIALIZED_ACCEPT\n");
135 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
136 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
138 #ifdef HAS_OTHER_CHILD
139 printf(" -D HAS_OTHER_CHILD\n");
141 #ifdef HAVE_RELIABLE_PIPED_LOGS
142 printf(" -D HAVE_RELIABLE_PIPED_LOGS\n");
145 printf(" -D BUFFERED_LOGS\n");
147 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
151 printf(" -D MULTITHREAD\n");
153 #ifdef CHARSET_EBCDIC
154 printf(" -D CHARSET_EBCDIC\n");
156 #ifdef NEED_HASHBANG_EMUL
157 printf(" -D NEED_HASHBANG_EMUL\n");
160 printf(" -D SHARED_CORE\n");
163 /* This list displays the compiled in default paths: */
165 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
168 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
170 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
171 printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
173 #ifdef DEFAULT_PIDLOG
174 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
176 #ifdef DEFAULT_SCOREBOARD
177 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
179 #ifdef DEFAULT_LOCKFILE
180 printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
182 #ifdef DEFAULT_XFERLOG
183 printf(" -D DEFAULT_XFERLOG=\"" DEFAULT_XFERLOG "\"\n");
185 #ifdef DEFAULT_ERRORLOG
186 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
188 #ifdef TYPES_CONFIG_FILE
189 printf(" -D TYPES_CONFIG_FILE=\"" TYPES_CONFIG_FILE "\"\n");
191 #ifdef SERVER_CONFIG_FILE
192 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
194 #ifdef ACCESS_CONFIG_FILE
195 printf(" -D ACCESS_CONFIG_FILE=\"" ACCESS_CONFIG_FILE "\"\n");
197 #ifdef RESOURCE_CONFIG_FILE
198 printf(" -D RESOURCE_CONFIG_FILE=\"" RESOURCE_CONFIG_FILE "\"\n");
202 static void destroy_and_exit_process(process_rec *process, int process_exit_value)
204 ap_destroy_pool(process->pool); /* and destroy all descendent pools */
205 exit(process_exit_value);
208 static process_rec *create_process(int argc, const char **argv)
210 process_rec *process;
215 ap_create_context(&cntx, NULL);
216 process = ap_palloc(cntx, sizeof(process_rec));
217 process->pool = cntx;
219 ap_create_context(&process->pconf, process->pool);
220 process->argc = argc;
221 process->argv = argv;
222 process->short_name = ap_filename_of_pathname(argv[0]);
226 static void usage(process_rec *process)
228 const char *bin = process->argv[0];
229 char pad[MAX_STRING_LEN];
232 for (i = 0; i < strlen(bin); i++)
236 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0,NULL , "Usage: %s [-R directory] [-D name] [-d directory] [-f file]", bin);
238 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Usage: %s [-D name] [-d directory] [-f file]", bin);
240 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-C \"directive\"] [-c \"directive\"]", pad);
242 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-k restart|shutdown|start]", pad);
243 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-n service_name]", pad);
244 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-i] [-u]", pad);
246 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]", pad);
247 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Options:");
249 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -R directory : specify an alternate location for shared object files");
251 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -D name : define a name for use in <IfDefine name> directives");
252 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -d directory : specify an alternate initial ServerRoot");
253 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -f file : specify an alternate ServerConfigFile");
254 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -C \"directive\" : process directive before reading config files");
255 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -c \"directive\" : process directive after reading config files");
257 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -n name : set service name and use its ServerConfigFile");
258 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k shutdown : tell running Apache to shutdown");
259 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k restart : tell running Apache to do a graceful restart");
260 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -k start : tell Apache to start");
261 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -i : install an Apache service");
262 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -u : uninstall an Apache service");
264 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -v : show version number");
265 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -V : show compile settings");
266 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -h : list available command line options (this page)");
267 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -l : list compiled in modules");
268 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -L : list available configuration directives");
269 /* TODOC: -S has been replaced by '-t -D DUMP_VHOSTS' */
270 /* ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -S : show parsed settings (currently only vhost settings)"); */
271 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -t : run syntax check for config files (with docroot check)");
272 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, " -T : run syntax check for config files (without docroot check)");
273 /* TODOC: -X goes away, expect MPMs to use -D options */
274 destroy_and_exit_process(process, 1);
281 ap_context_t *g_pHookPool;
284 API_EXPORT_NONSTD(int) apache_main(int argc, char *argv[])
286 API_EXPORT_NONSTD(int) main(int argc, char *argv[])
290 int configtestonly = 0;
291 const char *confname = SERVER_CONFIG_FILE;
292 const char *def_server_root = HTTPD_ROOT;
293 process_rec *process = create_process(argc, (const char **)argv);
294 server_rec *server_conf;
295 ap_context_t *pglobal = process->pool;
296 ap_context_t *pconf = process->pconf;
297 ap_context_t *plog; /* Pool of log streams, reset _after_ each read of conf */
298 ap_context_t *ptemp; /* Pool for temporary config stuff, reset often */
299 ap_context_t *pcommands; /* Pool for -C and -c switches */
305 ap_server_argv0 = process->short_name;
313 ap_setup_prelinked_modules(process);
315 ap_create_context(&pcommands, pglobal);
316 ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *));
317 ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
318 ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
320 while (ap_getopt(pcommands, argc, argv, "C:c:d:f:k:vVlLth", &c) == APR_SUCCESS) {
324 new = (char **)ap_push_array(ap_server_post_read_config);
325 *new = ap_pstrdup(pcommands, ap_optarg);
328 new = (char **)ap_push_array(ap_server_pre_read_config);
329 *new = ap_pstrdup(pcommands, ap_optarg);
332 def_server_root = ap_optarg;
335 confname = ap_optarg;
343 printf("Server version: %s\n", ap_get_server_version());
344 printf("Server built: %s\n", ap_get_server_built());
345 destroy_and_exit_process(process, 0);
347 show_compile_settings();
348 destroy_and_exit_process(process, 0);
351 destroy_and_exit_process(process, 0);
353 ap_show_directives();
354 destroy_and_exit_process(process, 0);
365 ap_create_context(&plog, pglobal);
366 ap_create_context(&ptemp, pconf);
368 /* Note that we preflight the config file once
369 before reading it _again_ in the main loop.
370 This allows things, log files configuration
371 for example, to settle down. */
373 ap_server_root = def_server_root;
374 ap_run_pre_config(pconf, plog, ptemp);
375 server_conf = ap_read_config(process, ptemp, confname);
376 if (configtestonly) {
377 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Syntax OK\n");
378 destroy_and_exit_process(process, 0);
382 ap_signal_parent(pconf, signal, ap_server_root);
383 destroy_and_exit_process(process, 0);
387 ap_run_open_logs(pconf, plog, ptemp, server_conf);
388 ap_post_config_hook(pconf, plog, ptemp, server_conf);
389 ap_destroy_pool(ptemp);
392 ap_clear_pool(pconf);
393 ap_create_context(&ptemp, pconf);
394 ap_server_root = def_server_root;
395 ap_run_pre_config(pconf, plog, ptemp);
396 server_conf = ap_read_config(process, ptemp, confname);
398 ap_run_open_logs(pconf, plog, ptemp, server_conf);
399 ap_post_config_hook(pconf, plog, ptemp, server_conf);
400 ap_destroy_pool(ptemp);
402 if (ap_mpm_run(pconf, plog, server_conf)) break;
404 destroy_and_exit_process(process, 0);
405 return 0; /* Supress compiler warning. */
408 /* force Expat to be linked into the server executable */
409 #if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP)
410 #include "xmlparse.h"
411 const XML_LChar *suck_in_expat(void);
412 const XML_LChar *suck_in_expat(void)
414 return XML_ErrorString(XML_ERROR_NONE);
416 #endif /* USE_EXPAT */
418 #ifndef SHARED_CORE_BOOTSTRAP
420 * Force ap_validate_password() into the image so that modules like
421 * mod_auth can use it even if they're dynamically loaded.
423 void suck_in_ap_validate_password(void);
424 void suck_in_ap_validate_password(void)
426 ap_validate_password("a", "b");