]> granicus.if.org Git - apache/blob - server/main.c
Remove obsolete ap_util_init function.
[apache] / server / main.c
1 /* ====================================================================
2  * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
3  * 
4  * Redistribution and use in source and binary forms, with or without 
5  * modification, are permitted provided that the following conditions 
6  * are met: 
7  * 
8  * 1. Redistributions of source code must retain the above copyright 
9  *    notice, this list of conditions and the following disclaimer.  
10  * 
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 
14  *    distribution. 
15  * 
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/)." 
20  * 
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 
24  *    apache@apache.org. 
25  * 
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. 
29  * 
30  * 6. Redistributions of any form whatsoever must retain the following 
31  *    acknowledgment: 
32  *    "This product includes software developed by the Apache Group 
33  *    for use in the Apache HTTP server project (http://www.apache.org/)." 
34  * 
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  * ==================================================================== 
48  * 
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/>. 
55  * 
56  */ 
57
58 #define CORE_PRIVATE
59 #include "httpd.h" 
60 #include "http_main.h" 
61 #include "http_config.h"
62 #include "util_uri.h" 
63 #include "ap_mpm.h"
64
65 char *ap_server_argv0;
66
67 API_VAR_EXPORT const char *ap_server_root;
68
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;
72
73 static void show_compile_settings(void)
74 {
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");
82 #endif
83 #ifdef SECURITY_HOLE_PASS_AUTHORIZATION
84     printf(" -D SECURITY_HOLE_PASS_AUTHORIZATION\n");
85 #endif
86 #ifdef HAVE_MMAP
87     printf(" -D HAVE_MMAP\n");
88 #endif
89 #ifdef HAVE_SHMGET
90     printf(" -D HAVE_SHMGET\n");
91 #endif
92 #ifdef USE_MMAP_SCOREBOARD
93     printf(" -D USE_MMAP_SCOREBOARD\n");
94 #endif
95 #ifdef USE_SHMGET_SCOREBOARD
96     printf(" -D USE_SHMGET_SCOREBOARD\n");
97 #endif
98 #ifdef USE_OS2_SCOREBOARD
99     printf(" -D USE_OS2_SCOREBOARD\n");
100 #endif
101 #ifdef USE_POSIX_SCOREBOARD
102     printf(" -D USE_POSIX_SCOREBOARD\n");
103 #endif
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);
108 #endif
109 #endif /*USE_MMAP_FILES*/
110 #ifdef NO_WRITEV
111     printf(" -D NO_WRITEV\n");
112 #endif
113 #ifdef NO_LINGCLOSE
114     printf(" -D NO_LINGCLOSE\n");
115 #endif
116 #ifdef USE_FCNTL_SERIALIZED_ACCEPT
117     printf(" -D USE_FCNTL_SERIALIZED_ACCEPT\n");
118 #endif
119 #ifdef USE_FLOCK_SERIALIZED_ACCEPT
120     printf(" -D USE_FLOCK_SERIALIZED_ACCEPT\n");
121 #endif
122 #ifdef USE_USLOCK_SERIALIZED_ACCEPT
123     printf(" -D USE_USLOCK_SERIALIZED_ACCEPT\n");
124 #endif
125 #ifdef USE_SYSVSEM_SERIALIZED_ACCEPT
126     printf(" -D USE_SYSVSEM_SERIALIZED_ACCEPT\n");
127 #endif
128 #ifdef USE_PTHREAD_SERIALIZED_ACCEPT
129     printf(" -D USE_PTHREAD_SERIALIZED_ACCEPT\n");
130 #endif
131 #ifdef SINGLE_LISTEN_UNSERIALIZED_ACCEPT
132     printf(" -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\n");
133 #endif
134 #ifdef HAS_OTHER_CHILD
135     printf(" -D HAS_OTHER_CHILD\n");
136 #endif
137 #ifdef NO_RELIABLE_PIPED_LOGS
138     printf(" -D NO_RELIABLE_PIPED_LOGS\n");
139 #endif
140 #ifdef BUFFERED_LOGS
141     printf(" -D BUFFERED_LOGS\n");
142 #ifdef PIPE_BUF
143         printf(" -D PIPE_BUF=%ld\n",(long)PIPE_BUF);
144 #endif
145 #endif
146 #ifdef MULTITHREAD
147     printf(" -D MULTITHREAD\n");
148 #endif
149 #ifdef CHARSET_EBCDIC
150     printf(" -D CHARSET_EBCDIC\n");
151 #endif
152 #ifdef NEED_HASHBANG_EMUL
153     printf(" -D NEED_HASHBANG_EMUL\n");
154 #endif
155 #ifdef SHARED_CORE
156     printf(" -D SHARED_CORE\n");
157 #endif
158
159 /* This list displays the compiled ap_context_t n default paths: */
160 #ifdef HTTPD_ROOT
161     printf(" -D HTTPD_ROOT=\"" HTTPD_ROOT "\"\n");
162 #endif
163 #ifdef SUEXEC_BIN
164     printf(" -D SUEXEC_BIN=\"" SUEXEC_BIN "\"\n");
165 #endif
166 #if defined(SHARED_CORE) && defined(SHARED_CORE_DIR)
167     printf(" -D SHARED_CORE_DIR=\"" SHARED_CORE_DIR "\"\n");
168 #endif
169 #ifdef DEFAULT_PIDLOG
170     printf(" -D DEFAULT_PIDLOG=\"" DEFAULT_PIDLOG "\"\n");
171 #endif
172 #ifdef DEFAULT_SCOREBOARD
173     printf(" -D DEFAULT_SCOREBOARD=\"" DEFAULT_SCOREBOARD "\"\n");
174 #endif
175 #ifdef DEFAULT_LOCKFILE
176     printf(" -D DEFAULT_LOCKFILE=\"" DEFAULT_LOCKFILE "\"\n");
177 #endif
178 #ifdef DEFAULT_XFERLOG
179     printf(" -D DEFAULT_XFERLOG=\"" DEFAULT_XFERLOG "\"\n");
180 #endif
181 #ifdef DEFAULT_ERRORLOG
182     printf(" -D DEFAULT_ERRORLOG=\"" DEFAULT_ERRORLOG "\"\n");
183 #endif
184 #ifdef TYPES_CONFIG_FILE
185     printf(" -D TYPES_CONFIG_FILE=\"" TYPES_CONFIG_FILE "\"\n");
186 #endif
187 #ifdef SERVER_CONFIG_FILE
188     printf(" -D SERVER_CONFIG_FILE=\"" SERVER_CONFIG_FILE "\"\n");
189 #endif
190 #ifdef ACCESS_CONFIG_FILE
191     printf(" -D ACCESS_CONFIG_FILE=\"" ACCESS_CONFIG_FILE "\"\n");
192 #endif
193 #ifdef RESOURCE_CONFIG_FILE
194     printf(" -D RESOURCE_CONFIG_FILE=\"" RESOURCE_CONFIG_FILE "\"\n");
195 #endif
196 }
197
198 static void usage(char *bin)
199 {
200     char pad[MAX_STRING_LEN];
201     unsigned i;
202
203     for (i = 0; i < strlen(bin); i++)
204         pad[i] = ' ';
205     pad[i] = '\0';
206 #ifdef SHARED_CORE
207     fprintf(stderr, "Usage: %s [-R directory] [-D name] [-d directory] [-f file]\n", bin);
208 #else
209     fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file]\n", bin);
210 #endif
211     fprintf(stderr, "       %s [-C \"directive\"] [-c \"directive\"]\n", pad);
212     fprintf(stderr, "       %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]\n", pad);
213     fprintf(stderr, "Options:\n");
214 #ifdef SHARED_CORE
215     fprintf(stderr, "  -R directory     : specify an alternate location for shared object files\n");
216 #endif
217     fprintf(stderr, "  -D name          : define a name for use in <IfDefine name> directives\n");
218     fprintf(stderr, "  -d directory     : specify an alternate initial ServerRoot\n");
219     fprintf(stderr, "  -f file          : specify an alternate ServerConfigFile\n");
220     fprintf(stderr, "  -C \"directive\"   : process directive before reading config files\n");
221     fprintf(stderr, "  -c \"directive\"   : process directive after  reading config files\n");
222     fprintf(stderr, "  -v               : show version number\n");
223     fprintf(stderr, "  -V               : show compile settings\n");
224     fprintf(stderr, "  -h               : list available command line options (this page)\n");
225     fprintf(stderr, "  -l               : list compiled ap_context_t n modules\n");
226     fprintf(stderr, "  -L               : list available configuration directives\n");
227     /* TODOC: -S has been replaced by '-t -D DUMP_VHOSTS' */
228     /* fprintf(stderr, "  -S               : show parsed settings (currently only vhost settings)\n"); */
229     fprintf(stderr, "  -t               : run syntax check for config files (with docroot check)\n");
230     fprintf(stderr, "  -T               : run syntax check for config files (without docroot check)\n");
231     /* TODOC: -X goes away, expect MPMs to use -D options */
232     exit(1);
233 }
234
235 ap_context_t *g_pHookPool;
236
237 extern char *optarg;
238
239 #ifdef WIN32
240 __declspec(dllexport)
241      int apache_main(int argc, char *argv[])
242 #else
243 int main(int argc, char **argv)
244 #endif
245 {
246     int c;
247     int configtestonly = 0;
248     char *s;
249     const char *confname = SERVER_CONFIG_FILE;
250     const char *def_server_root = HTTPD_ROOT;
251     server_rec *server_conf;
252     ap_context_t *pglobal;              /* Global pool */
253     ap_context_t *pconf;                /* Pool for config stuff */
254     ap_context_t *plog;                 /* Pool for error-logging files */
255     ap_context_t *ptemp;                /* Pool for temporart config stuff */
256     ap_context_t *pcommands;            /* Pool for -C and -c switches */
257
258     /* TODO: PATHSEPARATOR should be one of the os defines */
259 #define PATHSEPARATOR '/'
260     if ((s = strrchr(argv[0], PATHSEPARATOR)) != NULL) {
261         ap_server_argv0 = ++s;
262     }
263     else {
264         ap_server_argv0 = argv[0];
265     }
266
267     ap_util_uri_init();
268
269     ap_create_context(&pglobal, NULL);
270     g_pHookPool=pglobal;
271
272     ap_create_context(&pcommands, pglobal);
273     ap_server_pre_read_config  = ap_make_array(pcommands, 1, sizeof(char *));
274     ap_server_post_read_config = ap_make_array(pcommands, 1, sizeof(char *));
275     ap_server_config_defines   = ap_make_array(pcommands, 1, sizeof(char *));
276
277     ap_setup_prelinked_modules();
278
279     while ((c = getopt(argc, argv, "C:c:d:f:vVlLth")) != -1) {
280         char **new;
281         switch (c) {
282         case 'c':
283             new = (char **)ap_push_array(ap_server_post_read_config);
284             *new = ap_pstrdup(pcommands, optarg);
285             break;
286         case 'C':
287             new = (char **)ap_push_array(ap_server_pre_read_config);
288             *new = ap_pstrdup(pcommands, optarg);
289             break;
290         case 'd':
291             def_server_root = optarg;
292             break;
293         case 'f':
294             confname = optarg;
295             break;
296         case 'v':
297             printf("Server version: %s\n", ap_get_server_version());
298             printf("Server built:   %s\n", ap_get_server_built());
299             exit(0);
300         case 'V':
301             show_compile_settings();
302             exit(0);
303         case 'l':
304             ap_show_modules();
305             exit(0);
306         case 'L':
307             ap_show_directives();
308             exit(0);
309         case 't':
310             configtestonly = 1;
311             break;
312         case 'h':
313             usage(argv[0]);
314         case '?':
315             usage(argv[0]);
316         }
317     }
318
319     ap_create_context(&pconf, pglobal);
320     ap_create_context(&plog, pglobal);
321     ap_create_context(&ptemp, pconf);
322
323     /* for legacy reasons, we read the configuration twice before
324         we actually serve any requests */
325
326     ap_server_root = def_server_root;
327     ap_run_pre_config(pconf, plog, ptemp);
328     server_conf = ap_read_config(pconf, ptemp, confname);
329
330     if (configtestonly) {
331         fprintf(stderr, "Syntax OK\n");
332         exit(0);
333     }
334
335     ap_clear_pool(plog);
336     ap_run_open_logs(pconf, plog, ptemp, server_conf);
337     ap_post_config_hook(pconf, plog, ptemp, server_conf);
338     ap_clear_pool(ptemp);
339
340     for (;;) {
341         ap_clear_pool(pconf);
342         ap_create_context(&ptemp, pconf);
343         ap_server_root = def_server_root;
344         ap_run_pre_config(pconf, plog, ptemp);
345         server_conf = ap_read_config(pconf, ptemp, confname);
346         ap_clear_pool(plog);
347         ap_run_open_logs(pconf, plog, ptemp, server_conf);
348         ap_post_config_hook(pconf, plog, ptemp, server_conf);
349         ap_destroy_pool(ptemp);
350
351         if (ap_mpm_run(pconf, plog, server_conf)) break;
352     }
353
354     ap_clear_pool(pconf);
355     ap_clear_pool(plog);
356     ap_destroy_pool(pglobal);
357     exit(0);
358 }
359
360 /* force Expat to be linked into the server executable */
361 #if defined(USE_EXPAT) && !defined(SHARED_CORE_BOOTSTRAP)
362 #include "xmlparse.h"
363 const XML_LChar *suck_in_expat(void);
364 const XML_LChar *suck_in_expat(void)
365 {
366     return XML_ErrorString(XML_ERROR_NONE);
367 }
368 #endif /* USE_EXPAT */
369
370 #ifndef SHARED_CORE_BOOTSTRAP
371 /*
372  * Force ap_validate_password() into the image so that modules like
373  * mod_auth can use it even if they're dynamically loaded.
374  */
375 void suck_in_ap_validate_password(void);
376 void suck_in_ap_validate_password(void)
377 {
378     ap_validate_password("a", "b");
379 }
380 #endif
381