]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Ability to read the configuration file from an external program pipe
authorhno <>
Fri, 5 Apr 2002 04:17:24 +0000 (04:17 +0000)
committerhno <>
Fri, 5 Apr 2002 04:17:24 +0000 (04:17 +0000)
ChangeLog
doc/squid.8
src/cache_cf.cc

index ed09fad25da9d338b8ef24a4ccf094501545f801..9ca23e4399b8efd3bba9041d5d5d15a88ffac3dd 100644 (file)
--- 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 ():
 
index 8ee9aa846d03c3fafa58d28f254d81c7f59a2dc0..2ccc5f9bcb353b8d1c9b1de4dc683b00803bfc0d 100644 (file)
@@ -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"
index 35980304d421026894c083f5ff32d1aa3ea0890c..97afbac3d3ece94747729a484dae8ad47ef7917b 100644 (file)
@@ -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",