From: Eric Covener Date: Tue, 15 Nov 2016 03:50:42 +0000 (+0000) Subject: add an config section like X-Git-Tag: 2.5.0-alpha~1009 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3992a341127dcc371af45531f532d01547392bb;p=thirdparty%2Fapache%2Fhttpd.git add an config section like It allows a non httpd config file to be used as a marker directly in httpd.conf without hiding logic in a script in front of apachectl to do test -f and pass extra -D's. This is something we've had in IBM's httpd distro for a little bit and hadn't remembered to share. I've seen some questions/config files come up in a few places lately that would benefit from this as an option. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1769718 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index d6b03498b31..cf119061933 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) core: Add configuration section to allow any file on disk to be + used as a conditional. [Edward Lu, Eric Covener] + *) event: Avoid listener periodic wake ups by using the pollset wake-ability when available. PR 57399. [Yann Ylavic, Luca Toscano] diff --git a/docs/manual/mod/core.xml b/docs/manual/mod/core.xml index 87d53c1c8c8..a81e7e1d1f2 100644 --- a/docs/manual/mod/core.xml +++ b/docs/manual/mod/core.xml @@ -2240,6 +2240,43 @@ if a test is true at startup + +IfFile +Encloses directives that will be processed only +if file exists at startup +<IfFile [!]parameter-name> ... + </IfFile> +server configvirtual host +directory.htaccess + + + +

The <IfFile filename>...</IfFile> + section is used to mark directives that are conditional on + the existence of a file on disk. The directives within an + IfFile section are only + processed if the filename exists. If filename + doesn't exist, everything between the start and end markers is + ignored. filename can be an absolute path or a path + relative to the server root.

+ +

The filename in the IfFile + section directive can take the same forms as the + test variable in the IfDefine + section, i.e. the test can be negated if the + ! character is placed directly before filename. +

+ +

If a relative filename is supplied, the check is + ServerRoot relative. In the case where + this directive occurs before the ServerRoot, + the path will be checked relative to the compiled-in server root or + the server root passed in on the command line via the -d + parameter.

+ +
+
+ IfModule Encloses directives that are processed conditional on the diff --git a/server/core.c b/server/core.c index ff203daf317..f8027696494 100644 --- a/server/core.c +++ b/server/core.c @@ -2851,6 +2851,49 @@ static const char *start_ifdefine(cmd_parms *cmd, void *dummy, const char *arg) } } +static const char *start_iffile(cmd_parms *cmd, void *dummy, const char *arg) +{ + apr_finfo_t sb; + const char *endp; + int file_exists = 0; + int not = 0; + const char *relative; + + endp = ap_strrchr_c(arg, '>'); + if (endp == NULL) { + return unclosed_directive(cmd); + } + + arg = apr_pstrndup(cmd->temp_pool, arg, endp - arg); + + if (arg[0] == '!') { + not = 1; + arg++; + } + + if (!arg[0]) { + return missing_container_arg(cmd); + } + + relative = ap_server_root_relative(cmd->temp_pool, arg); + file_exists = (apr_stat(&sb, relative, 0, cmd->pool) == APR_SUCCESS); + + if ((!not && file_exists) || (not && !file_exists)) { + ap_directive_t *parent = NULL; + ap_directive_t *current = NULL; + const char *retval; + + retval = ap_build_cont_config(cmd->pool, cmd->temp_pool, cmd, + ¤t, &parent, " business */ static const char *virtualhost_section(cmd_parms *cmd, void *dummy, @@ -4464,6 +4507,8 @@ AP_INIT_TAKE1("