dougm 98/01/11 12:25:07
Modified: . STATUS src CHANGES src/main http_conf_globals.h http_config.c http_main.c util.c Log: added Doug's [PATCH] add -c and -C switches (take 3) added Paul's WIN32: patch to allow for Doug's -c option Submitted by: Doug MacEachern Reviewed by: Ben, Paul, Martin Revision Changes Path 1.74 +2 -8 apachen/STATUS Index: STATUS =================================================================== RCS file: /export/home/cvs/apachen/STATUS,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- STATUS 1998/01/11 18:30:08 1.73 +++ STATUS 1998/01/11 20:24:57 1.74 @@ -74,6 +74,8 @@ * Dean's [PATCH] make mod_include use ap_cpystrn * WIN32: fix proxy caching * WIN32: fix CGI scripts called w/o '=' in path info PR#1591 + * Doug's [PATCH] add -c and -C switches (take 3) + * Paul's WIN32: patch to allow for Doug's -c option Available Patches: @@ -100,14 +102,6 @@ * Dean's [PATCH] yet another slow function <[EMAIL PROTECTED]> Status: Dean +1, Jim +1, Martin +1, Paul +1 - - * Doug's [PATCH] add -c and -C switches (take 3) - <[EMAIL PROTECTED]> - Doug, Randy and Jim were +1 on original -MApache::httpd_conf - patch, which was recinded in favor of this patch prompted by - ideas from Ben and Dean. Marc, Ken and Jim were also in favor - of this over -M - Status: Doug +1, Martin +1, Ben +1, Paul +1 * Brian Havard's [Patch] OS/2 - fix up shut down <[EMAIL PROTECTED]> 1.562 +8 -0 apachen/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apachen/src/CHANGES,v retrieving revision 1.561 retrieving revision 1.562 diff -u -r1.561 -r1.562 --- CHANGES 1998/01/10 05:46:32 1.561 +++ CHANGES 1998/01/11 20:24:58 1.562 @@ -1,5 +1,13 @@ Changes with Apache 1.3b4 + *) new -C and -c command line arguments + usage: + -C "directive" : process directive before reading config files + -c "directive" : process directive after reading config files + example: + httpd -C "PerlModule Apache::httpd_conf" + [Doug MacEachern] + *) WIN32: Fix the execution of CGIs that are scripts and called with path info that does not have an '=' in. (eg. http://server/cgi-bin/printenv?foobar) PR#1591 1.22 +4 -0 apachen/src/main/http_conf_globals.h Index: http_conf_globals.h =================================================================== RCS file: /export/home/cvs/apachen/src/main/http_conf_globals.h,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- http_conf_globals.h 1998/01/07 16:46:02 1.21 +++ http_conf_globals.h 1998/01/11 20:25:01 1.22 @@ -88,6 +88,10 @@ extern char server_root[MAX_STRING_LEN]; extern char server_confname[MAX_STRING_LEN]; +/* for -C and -c switches */ +extern array_header *server_pre_read_config; +extern array_header *server_post_read_config; + /* We want this to have the least chance of being corrupted if there * is some memory corruption, so we allocate it statically. */ 1.92 +47 -0 apachen/src/main/http_config.c Index: http_config.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/http_config.c,v retrieving revision 1.91 retrieving revision 1.92 diff -u -r1.91 -r1.92 --- http_config.c 1998/01/07 16:46:03 1.91 +++ http_config.c 1998/01/11 20:25:03 1.92 @@ -900,6 +900,42 @@ return make_full_path(p, server_root, file); } +void process_command_config(server_rec *s, array_header *arr, pool *p, pool *ptemp) +{ + const char *errmsg; + cmd_parms parms; + int i; + char **lines = (char **)arr->elts; + + parms = default_parms; + parms.pool = p; + parms.temp_pool = ptemp; + parms.server = s; + parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT); + parms.config_file = pcfg_openfile(p, NULL); + + for (i = 0; i < arr->nelts; ++i) { + char *line = lines[i]; + +#ifdef MOD_PERL + if(!(strncmp(line, "PerlModule ", 11))) { + const char *perl_cmd_module(cmd_parms *parms, void *dummy, char *arg); + line += 11; + (void)perl_cmd_module(&parms, s->lookup_defaults, line); + continue; + } +#endif + + errmsg = handle_command(&parms, s->lookup_defaults, line); + + if (errmsg) { + fprintf(stderr, "Syntax error in command: `%s'\n", lines[i]); + fprintf(stderr, "%s\n", errmsg); + exit(1); + } + } +} + void process_resource_config(server_rec *s, char *fname, pool *p, pool *ptemp) { const char *errmsg; @@ -914,6 +950,13 @@ return; } + /* don't require conf/httpd.conf if we have a -C or -c switch */ + if((server_pre_read_config->nelts || server_post_read_config->nelts) && + !(strcmp(fname, server_root_relative(p, SERVER_CONFIG_FILE)))) { + if (stat(fname, &finfo) == -1) + return; + } + /* GCC's initialization extensions are soooo nice here... */ parms = default_parms; @@ -1193,9 +1236,13 @@ /* All server-wide config files now have the SAME syntax... */ + process_command_config(s, server_pre_read_config, p, ptemp); + process_resource_config(s, confname, p, ptemp); process_resource_config(s, s->srm_confname, p, ptemp); process_resource_config(s, s->access_confname, p, ptemp); + + process_command_config(s, server_post_read_config, p, ptemp); fixup_virtual_hosts(p, s); default_listeners(p, s); 1.265 +24 -5 apachen/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/http_main.c,v retrieving revision 1.264 retrieving revision 1.265 diff -u -r1.264 -r1.265 --- http_main.c 1998/01/11 16:51:32 1.264 +++ http_main.c 1998/01/11 20:25:04 1.265 @@ -231,6 +231,9 @@ char server_confname[MAX_STRING_LEN]; char coredump_dir[MAX_STRING_LEN]; +array_header *server_pre_read_config; +array_header *server_post_read_config; + /* *Non*-shared http_main globals... */ server_rec *server_conf; @@ -278,6 +281,7 @@ static pool *pconf; /* Pool for config stuff */ static pool *ptrans; /* Pool for per-transaction stuff */ static pool *pchild; /* Pool for httpd child stuff */ +static pool *pcommands; /* Pool for -C and -c switches */ int APACHE_TLS my_pid; /* it seems silly to call getpid all the time */ #ifndef MULTITHREAD @@ -743,9 +747,11 @@ void usage(char *bin) { - fprintf(stderr, "Usage: %s [-d directory] [-f file] [-v] [-h] [-l]\n", bin); + fprintf(stderr, "Usage: %s [-d directory] [-f file] [-C \"directive\"] [-c \"directive\"] [-v] [-h] [-l]\n", bin); fprintf(stderr, "-d directory : specify an alternate initial ServerRoot\n"); fprintf(stderr, "-f file : specify an alternate ServerConfigFile\n"); + fprintf(stderr, "-C \"directive\" : process directive before reading config files\n"); + fprintf(stderr, "-c \"directive\" : process directive after reading config files\n"); fprintf(stderr, "-v : show version number\n"); fprintf(stderr, "-V : show compile settings\n"); fprintf(stderr, "-h : list directives\n"); @@ -3606,14 +3612,27 @@ pconf = permanent_pool; ptrans = make_sub_pool(pconf); + pcommands = make_sub_pool(NULL); + server_pre_read_config = make_array(pcommands, 1, sizeof(char *)); + server_post_read_config = make_array(pcommands, 1, sizeof(char *)); + server_argv0 = argv[0]; ap_cpystrn(server_root, HTTPD_ROOT, sizeof(server_root)); ap_cpystrn(server_confname, SERVER_CONFIG_FILE, sizeof(server_confname)); setup_prelinked_modules(); - while ((c = getopt(argc, argv, "Xd:f:vVhlZ:")) != -1) { + while ((c = getopt(argc, argv, "C:c:Xd:f:vVhlZ:")) != -1) { + char **new; switch (c) { + case 'c': + new = (char **)push_array(server_post_read_config); + *new = pstrdup(pcommands, optarg); + break; + case 'C': + new = (char **)push_array(server_pre_read_config); + *new = pstrdup(pcommands, optarg); + break; case 'd': ap_cpystrn(server_root, optarg, sizeof(server_root)); break; @@ -4456,7 +4475,7 @@ ap_assert(*ev); pass_argv[0] = argv[0]; - pass_argv[1] = "-c"; + pass_argv[1] = "-Z"; pass_argv[2] = buf; for (i = 1; i < argc; i++) { pass_argv[i + 2] = argv[i]; @@ -4731,10 +4750,10 @@ setup_prelinked_modules(); - while ((c = getopt(argc, argv, "Xd:f:vVhlc:ius")) != -1) { + while ((c = getopt(argc, argv, "Xd:f:vVhlZ:ius")) != -1) { switch (c) { #ifdef WIN32 - case 'c': + case 'Z': exit_event = open_event(optarg); APD2("child: opened process event %s", optarg); cp = strchr(optarg, '_'); 1.83 +10 -4 apachen/src/main/util.c Index: util.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/util.c,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- util.c 1998/01/07 16:46:21 1.82 +++ util.c 1998/01/11 20:25:05 1.83 @@ -672,14 +672,20 @@ API_EXPORT(configfile_t *) pcfg_openfile(pool *p, const char *name) { configfile_t *new_cfg; - FILE *file = fopen(name, "r"); + FILE *file; #ifdef DEBUG - aplog_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, "Opening config file %s (%s)", name, file == NULL ? strerror(errno) : "successful"); + aplog_error(APLOG_MARK, APLOG_DEBUG|APLOG_NOERRNO, NULL, + "Opening config file %s (%s)", + name ? name : "NULL", + (name && (file == NULL)) ? strerror(errno) : "successful"); #endif - if (file == NULL) - return NULL; + if (name != NULL) { + file = fopen(name, "r"); + if (file == NULL) + return NULL; + } new_cfg = palloc(p, sizeof (*new_cfg)); new_cfg->param = file;