From: hno <> Date: Fri, 5 Apr 2002 04:17:24 +0000 (+0000) Subject: Ability to read the configuration file from an external program pipe X-Git-Tag: SQUID_3_0_PRE1~1131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1741cbadf26d175db78d9ade890f1bbc2eb75840;p=thirdparty%2Fsquid.git Ability to read the configuration file from an external program pipe --- diff --git a/ChangeLog b/ChangeLog index ed09fad25d..9ca23e4399 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ Changes to squid-2.6 (): - CARP now plays well with the other peering algorithms + - Configuration file can be read from an external program + or preprocessor. See squid.8 man page. Changes to squid-2.5 (): diff --git a/doc/squid.8 b/doc/squid.8 index 8ee9aa846d..2ccc5f9bcb 100644 --- a/doc/squid.8 +++ b/doc/squid.8 @@ -67,7 +67,11 @@ Specify HTTP port number (default: 3128). Write debugging to stderr also. .IP "-f file" Use the given config-file instead of -.I /etc/squid/squid.conf +.IR /etc/squid/squid.conf . +If the file name starts with a ! or | then it is assumed to be an external +command or command line. Can for example be used to pre-process the +configuration before it is being read by Squid. To facilitate this Squid +also understands the common #line notion to indicate the real source file. .IP -h Print help message. .IP "-k reconfigure | rotate | shutdown | interrupt | kill | debug | check | parse" diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 35980304d4..97afbac3d3 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.402 2002/04/04 21:03:46 hno Exp $ + * $Id: cache_cf.cc,v 1.403 2002/04/04 21:17:25 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -237,16 +237,25 @@ parseConfigFile(const char *file_name) char *token = NULL; char *tmp_line; int err_count = 0; + int is_pipe = 0; configFreeMemory(); default_all(); - if ((fp = fopen(file_name, "r")) == NULL) + if (file_name[0] == '!' || file_name[0] == '|') { + fp = popen(file_name + 1, "r"); + is_pipe = 1; + } else { + fp = fopen(file_name, "r"); + } + if (fp == NULL) fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); #if defined(_SQUID_CYGWIN_) setmode(fileno(fp), O_TEXT); #endif cfg_filename = file_name; - if ((token = strrchr(cfg_filename, '/'))) + if (is_pipe) + cfg_filename = file_name + 1; + else if ((token = strrchr(cfg_filename, '/'))) cfg_filename = token + 1; memset(config_input_line, '\0', BUFSIZ); config_lineno = 0; @@ -254,6 +263,30 @@ parseConfigFile(const char *file_name) config_lineno++; if ((token = strchr(config_input_line, '\n'))) *token = '\0'; + if (strncmp(config_input_line, "#line ", 6) == 0) { + static char new_file_name[1024]; + static char *file; + static char new_lineno; + token = config_input_line + 6; + new_lineno = strtol(token, &file, 0) - 1; + if (file == token) + continue; /* Not a valid #line directive, may be a comment */ + while (*file && isspace((unsigned char) *file)) + file++; + if (*file) { + if (*file != '"') + continue; /* Not a valid #line directive, may be a comment */ + xstrncpy(new_file_name, file + 1, sizeof(new_file_name)); + if ((token = strchr(new_file_name, '"'))) + *token = '\0'; + cfg_filename = new_file_name; +#if PROBABLY_NOT_WANTED_HERE + if ((token = strrchr(cfg_filename, '/'))) + cfg_filename = token + 1; +#endif + } + config_lineno = new_lineno; + } if (config_input_line[0] == '#') continue; if (config_input_line[0] == '\0') @@ -261,14 +294,21 @@ parseConfigFile(const char *file_name) debug(3, 5) ("Processing: '%s'\n", config_input_line); tmp_line = xstrdup(config_input_line); if (!parse_line(tmp_line)) { - debug(3, 0) ("parseConfigFile: line %d unrecognized: '%s'\n", + debug(3, 0) ("parseConfigFile: '%s' line %d unrecognized: '%s'\n", + cfg_filename, config_lineno, config_input_line); err_count++; } safe_free(tmp_line); } - fclose(fp); + if (is_pipe) { + int ret = pclose(fp); + if (ret != 0) + fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret); + } else { + fclose(fp); + } defaults_if_none(); configDoConfigure(); cachemgrRegister("config",