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/>.
60 #include "http_main.h"
61 #include "http_config.h"
65 char *ap_server_argv0;
67 API_VAR_EXPORT const char *ap_server_root;
69 ap_array_header_t *ap_server_pre_read_config;
70 ap_array_header_t *ap_server_post_read_config;
71 ap_array_header_t *ap_server_config_defines;
73 static void show_compile_settings(void)
75 printf("Server version: %s\n", ap_get_server_version());
76 printf("Server built: %s\n", ap_get_server_built());
77 printf("Server's Module Magic Number: %u:%u\n",
78 MODULE_MAGIC_NUMBER_MAJOR, MODULE_MAGIC_NUMBER_MINOR);
79 printf("Server compiled with....\n");
80 #ifdef BIG_SECURITY_HOLE
81 printf(" -D BIG_SECURITY_HOLE\n");
83 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
84 printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
87 printf(" -D HAVE_MMAP\n");
90 printf(" -D HAVE_SHMGET\n");
92 #ifdef USE_MMAP_SCOREBOARD
93 printf(" -D USE_MMAP_SCOREBOARD\n");
95 #ifdef USE_SHMGET_SCOREBOARD
96 printf(" -D USE_SHMGET_SCOREBOARD\n");
98 #ifdef USE_OS2_SCOREBOARD
99 printf(" -D USE_OS2_SCOREBOARD\n");
101 #ifdef USE_POSIX_SCOREBOARD
102 printf(" -D USE_POSIX_SCOREBOARD\n");
104 #ifdef USE_MMAP_FILES
105 printf(" -D USE_MMAP_FILES\n");
106 #ifdef MMAP_SEGMENT_SIZE
107 printf(" -D MMAP_SEGMENT_SIZE=%ld\n",(long)MMAP_SEGMENT_SIZE);
109 #endif /*USE_MMAP_FILES*/
111 printf(" -D NO_WRITEV\n");
114 printf(" -D NO_LINGCLOSE\n");
116 #ifdef USE_FCNTL_SERIALIZED_ACCEPT
117 printf(" -D USE_FCNTL_SERIALIZED_ACCEPT\n");
119 #ifdef USE_FLOCK_SERIALIZED_ACCEPT
120 printf(" -D USE_FLOCK_SERIALIZED_ACCEPT\n");
122 #ifdef USE_USLOCK_SERIALIZED_ACCEPT
123 printf(" -D USE_USLOCK_SERIALIZED_ACCEPT\n");
125 #ifdef USE_SYSVSEM_SERIALIZED_ACCEPT
126 printf(" -D USE_SYSVSEM_SERIALIZED_ACCEPT\n");
128 #ifdef USE_PTHREAD_SERIALIZED_ACCEPT
129 printf(" -D USE_PTHREAD_SERIALIZED_ACCEPT\n");
131 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
132 printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
134 #ifdef HAS_OTHER_CHILD
135 printf(" -D HAS_OTHER_CHILD\n");
137 #ifdef NO_RELIABLE_PIPED_LOGS
138 printf(" -D NO_RELIABLE_PIPED_LOGS\n");
141 printf(" -D BUFFERED_LOGS\n");
143 printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
147 printf(" -D MULTITHREAD\n");
149 #ifdef CHARSET_EBCDIC
150 printf(" -D CHARSET_EBCDIC\n");
152 #ifdef NEED_HASHBANG_EMUL
153 printf(" -D NEED_HASHBANG_EMUL\n");
156 printf(" -D SHARED_CORE\n");
159 /* This list displays the compiled in default paths: */
161 printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
164 printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
166 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
167 printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
169 #ifdef DEFAULT_PIDLOG
170 printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
172 #ifdef DEFAULT_SCOREBOARD
173 printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
175 #ifdef DEFAULT_LOCKFILE
176 printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
178 #ifdef DEFAULT_XFERLOG
179 printf(" -D DEFAULT_XFERLOG=\"" DEFAULT_XFERLOG "\"\n");
181 #ifdef DEFAULT_ERRORLOG
182 printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
184 #ifdef TYPES_CONFIG_FILE
185 printf(" -D TYPES_CONFIG_FILE=\"" TYPES_CONFIG_FILE "\"\n");
187 #ifdef SERVER_CONFIG_FILE
188 printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
190 #ifdef ACCESS_CONFIG_FILE
191 printf(" -D ACCESS_CONFIG_FILE=\"" ACCESS_CONFIG_FILE "\"\n");
193 #ifdef RESOURCE_CONFIG_FILE
194 printf(" -D RESOURCE_CONFIG_FILE=\"" RESOURCE_CONFIG_FILE "\"\n");
198 static void destroy_and_exit_process(process_rec *process, int process_exit_value)
200 ap_destroy_pool(process->pool); /* and destroy all descendent pools */
201 exit(process_exit_value);
204 #define PATHSEPARATOR '/' /* Belongs in some apr os include file */
206 static process_rec *create_process(int argc, const char **argv)
208 process_rec *process;
213 ap_create_context(&cntx, NULL);
214 process = ap_palloc(cntx, sizeof(process_rec));
215 process->pool = cntx;
217 ap_create_context(&process->pconf, process->pool);
218 process->argc = argc;
219 process->argv = argv;
221 char *s = strrchr(argv[0], PATHSEPARATOR);
223 process->short_name = s ? ++s : argv[0];
228 static void usage(process_rec *process)
230 const char *bin = process->argv[0];
231 char pad[MAX_STRING_LEN];
234 for (i = 0; i < strlen(bin); i++)
238 fprintf(stderr, "Usage: %s [-R directory] [-D name] [-d directory] [-f file]\n", bin);
240 fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file]\n", bin);
242 fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"]\n", pad);
243 fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]\n", pad);
244 fprintf(stderr, "Options:\n");
246 fprintf(stderr, " -R directory : specify an alternate location for shared object files\n");
248 fprintf(stderr, " -D name : define a name for use in <IfDefine name> directives\n");
249 fprintf(stderr, " -d directory : specify an alternate initial ServerRoot\n");
250 fprintf(stderr, " -f file : specify an alternate ServerConfigFile\n");
251 fprintf(stderr, " -C \"directive\" : process directive before reading config files\n");
252 fprintf(stderr, " -c \"directive\" : process directive after reading config files\n");
253 fprintf(stderr, " -v : show version number\n");
254 fprintf(stderr, " -V : show compile settings\n");
255 fprintf(stderr, " -h : list available command line options (this page)\n");
256 fprintf(stderr, " -l : list compiled in modules\n");
257 fprintf(stderr, " -L : list available configuration directives\n");
258 /* TODOC: -S has been replaced by '-t -D DUMP_VHOSTS' */
259 /* fprintf(stderr, " -S : show parsed settings (currently only vhost settings)\n"); */
260 fprintf(stderr, " -t : run syntax check for config files (with docroot check)\n");
261 fprintf(stderr, " -T : run syntax check for config files (without docroot check)\n");
262 /* TODOC: -X goes away, expect MPMs to use -D options */
263 destroy_and_exit_process(process, 1);
270 ap_context_t *g_pHookPool;
275 API_EXPORT_NONSTD(int) apache_main(int argc, char *argv[])
277 API_EXPORT_NONSTD(int) main(int argc, char *argv[])
281 int configtestonly = 0;
282 const char *confname = SERVER_CONFIG_FILE;
283 const char *def_server_root = HTTPD_ROOT;
284 process_rec *process = create_process(argc, (const char **)argv);
285 server_rec *server_conf;
286 ap_context_t *pglobal = process->pool;
287 ap_context_t *pconf = process->pconf;
288 ap_context_t *plog; /* Pool for error-logging files */
289 ap_context_t *ptemp; /* Pool for temporary config stuff */
290 ap_context_t *pcommands; /* Pool for -C and -c switches */
293 if ((ap_server_argv0 = strrchr(argv[0], '/')) != NULL)
295 if ((ap_server_argv0 = strrchr(argv[0], '\\')) != NULL)
299 ap_server_argv0 = argv[0];
305 ap_setup_prelinked_modules(process);
307 ap_create_context(&pcommands, pglobal);
308 ap_server_pre_read_config = ap_make_array(pcommands, 1, sizeof(char *));
309 ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
310 ap_server_config_defines = ap_make_array(pcommands, 1, sizeof(char *));
312 while ((c = getopt(argc, argv, "C:c:d:f:vVlLth")) != -1) {
316 new = (char **)ap_push_array(ap_server_post_read_config);
317 *new = ap_pstrdup(pcommands, optarg);
320 new = (char **)ap_push_array(ap_server_pre_read_config);
321 *new = ap_pstrdup(pcommands, optarg);
324 def_server_root = optarg;
330 printf("Server version: %s\n", ap_get_server_version());
331 printf("Server built: %s\n", ap_get_server_built());
332 destroy_and_exit_process(process, 0);
334 show_compile_settings();
335 destroy_and_exit_process(process, 0);
338 destroy_and_exit_process(process, 0);
340 ap_show_directives();
341 destroy_and_exit_process(process, 0);
352 ap_create_context(&plog, pglobal);
353 ap_create_context(&ptemp, pconf);
355 /* for legacy reasons, we read the configuration twice before
356 we actually serve any requests */
358 ap_server_root = def_server_root;
359 ap_run_pre_config(pconf, plog, ptemp);
360 server_conf = ap_read_config(process, ptemp, confname);
362 if (configtestonly) {
363 fprintf(stderr, "Syntax OK\n");
364 destroy_and_exit_process(process, 0);
368 ap_run_open_logs(pconf, plog, ptemp, server_conf);
369 ap_post_config_hook(pconf, plog, ptemp, server_conf);
370 ap_destroy_pool(ptemp);
373 ap_clear_pool(pconf);
374 ap_create_context(&ptemp, pconf);
375 ap_server_root = def_server_root;
376 ap_run_pre_config(pconf, plog, ptemp);
377 server_conf = ap_read_config(process, ptemp, confname);
379 ap_run_open_logs(pconf, plog, ptemp, server_conf);
380 ap_post_config_hook(pconf, plog, ptemp, server_conf);
381 ap_destroy_pool(ptemp);
383 if (ap_mpm_run(pconf, plog, server_conf)) break;
385 destroy_and_exit_process(process, 0);
386 return 0; /* Supress compiler warning. */
389 /* force Expat to be linked into the server executable */
390 #if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP)
391 #include "xmlparse.h"
392 const XML_LChar *suck_in_expat(void);
393 const XML_LChar *suck_in_expat(void)
395 return XML_ErrorString(XML_ERROR_NONE);
397 #endif /* USE_EXPAT */
399 #ifndef SHARED_CORE_BOOTSTRAP
401 * Force ap_validate_password() into the image so that modules like
402 * mod_auth can use it even if they're dynamically loaded.
404 void suck_in_ap_validate_password(void);
405 void suck_in_ap_validate_password(void)
407 ap_validate_password("a", "b");