bdaebd
# ./pullrev.sh 1842929 1842931 1852982 1853631 1857731
bdaebd
http://svn.apache.org/viewvc?view=revision&revision=1842929
bdaebd
http://svn.apache.org/viewvc?view=revision&revision=1842931
bdaebd
http://svn.apache.org/viewvc?view=revision&revision=1852982
bdaebd
http://svn.apache.org/viewvc?view=revision&revision=1857731
bdaebd
http://svn.apache.org/viewvc?view=revision&revision=1853631
bdaebd
bdaebd
diff --git a/Makefile.in b/Makefile.in
bdaebd
index 06b8c5a..9eeb5c7 100644
bdaebd
--- a/Makefile.in
bdaebd
+++ b/Makefile.in
bdaebd
@@ -213,6 +213,7 @@ install-cgi:
bdaebd
 install-other:
bdaebd
 	@test -d $(DESTDIR)$(logfiledir) || $(MKINSTALLDIRS) $(DESTDIR)$(logfiledir)
bdaebd
 	@test -d $(DESTDIR)$(runtimedir) || $(MKINSTALLDIRS) $(DESTDIR)$(runtimedir)
bdaebd
+	@test -d $(DESTDIR)$(statedir) || $(MKINSTALLDIRS) $(DESTDIR)$(statedir)
bdaebd
 	@for ext in dll x; do \
bdaebd
 		file=apachecore.$$ext; \
bdaebd
 		if test -f $$file; then \
bdaebd
diff --git a/acinclude.m4 b/acinclude.m4
bdaebd
index 0ad0c13..a8c2804 100644
bdaebd
--- a/acinclude.m4
bdaebd
+++ b/acinclude.m4
bdaebd
@@ -45,6 +45,7 @@ AC_DEFUN([APACHE_GEN_CONFIG_VARS],[
bdaebd
   APACHE_SUBST(installbuilddir)
bdaebd
   APACHE_SUBST(runtimedir)
bdaebd
   APACHE_SUBST(proxycachedir)
bdaebd
+  APACHE_SUBST(statedir)
bdaebd
   APACHE_SUBST(other_targets)
bdaebd
   APACHE_SUBST(progname)
bdaebd
   APACHE_SUBST(prefix)
bdaebd
@@ -663,6 +664,7 @@ AC_DEFUN([APACHE_EXPORT_ARGUMENTS],[
bdaebd
   APACHE_SUBST_EXPANDED_ARG(runtimedir)
bdaebd
   APACHE_SUBST_EXPANDED_ARG(logfiledir)
bdaebd
   APACHE_SUBST_EXPANDED_ARG(proxycachedir)
bdaebd
+  APACHE_SUBST_EXPANDED_ARG(statedir)
bdaebd
 ])
bdaebd
 
bdaebd
 dnl 
bdaebd
diff --git a/configure.in b/configure.in
bdaebd
index a208b53..de6a8ad 100644
bdaebd
--- a/configure.in
bdaebd
+++ b/configure.in
bdaebd
@@ -41,7 +41,7 @@ dnl Something seems broken here.
bdaebd
 AC_PREFIX_DEFAULT(/usr/local/apache2)
bdaebd
 
bdaebd
 dnl Get the layout here, so we can pass the required variables to apr
bdaebd
-APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir])
bdaebd
+APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir statedir])
bdaebd
 
bdaebd
 dnl reparse the configure arguments.
bdaebd
 APR_PARSE_ARGUMENTS
bdaebd
diff --git a/include/ap_config_layout.h.in b/include/ap_config_layout.h.in
bdaebd
index 2b4a70c..e076f41 100644
bdaebd
--- a/include/ap_config_layout.h.in
bdaebd
+++ b/include/ap_config_layout.h.in
bdaebd
@@ -60,5 +60,7 @@
bdaebd
 #define DEFAULT_REL_LOGFILEDIR "@rel_logfiledir@"
bdaebd
 #define DEFAULT_EXP_PROXYCACHEDIR "@exp_proxycachedir@"
bdaebd
 #define DEFAULT_REL_PROXYCACHEDIR "@rel_proxycachedir@"
bdaebd
+#define DEFAULT_EXP_STATEDIR "@exp_statedir@"
bdaebd
+#define DEFAULT_REL_STATEDIR "@rel_statedir@"
bdaebd
 
bdaebd
 #endif /* AP_CONFIG_LAYOUT_H */
bdaebd
diff --git a/include/http_config.h b/include/http_config.h
bdaebd
index adc5825..effccc1 100644
bdaebd
--- a/include/http_config.h
bdaebd
+++ b/include/http_config.h
bdaebd
@@ -757,6 +757,14 @@ AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname);
bdaebd
  */
bdaebd
 AP_DECLARE(char *) ap_runtime_dir_relative(apr_pool_t *p, const char *fname);
bdaebd
 
bdaebd
+/**
bdaebd
+ * Compute the name of a persistent state file (e.g. a database or
bdaebd
+ * long-lived cache) relative to the appropriate state directory.
bdaebd
+ * Absolute paths are returned as-is.  The state directory is
bdaebd
+ * configured via the DefaultStateDir directive or at build time.
bdaebd
+ */
bdaebd
+AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *fname);
bdaebd
+
bdaebd
 /* Finally, the hook for dynamically loading modules in... */
bdaebd
 
bdaebd
 /**
bdaebd
diff --git a/modules/dav/fs/mod_dav_fs.c b/modules/dav/fs/mod_dav_fs.c
bdaebd
index addfd7e..2389f8f 100644
bdaebd
--- a/modules/dav/fs/mod_dav_fs.c
bdaebd
+++ b/modules/dav/fs/mod_dav_fs.c
bdaebd
@@ -29,6 +29,10 @@ typedef struct {
bdaebd
 
bdaebd
 extern module AP_MODULE_DECLARE_DATA dav_fs_module;
bdaebd
 
bdaebd
+#ifndef DEFAULT_DAV_LOCKDB
bdaebd
+#define DEFAULT_DAV_LOCKDB "davlockdb"
bdaebd
+#endif
bdaebd
+
bdaebd
 const char *dav_get_lockdb_path(const request_rec *r)
bdaebd
 {
bdaebd
     dav_fs_server_conf *conf;
bdaebd
@@ -57,6 +61,24 @@ static void *dav_fs_merge_server_config(apr_pool_t *p,
bdaebd
     return newconf;
bdaebd
 }
bdaebd
 
bdaebd
+static apr_status_t dav_fs_post_config(apr_pool_t *p, apr_pool_t *plog,
bdaebd
+                                       apr_pool_t *ptemp, server_rec *base_server)
bdaebd
+{
bdaebd
+    server_rec *s;
bdaebd
+
bdaebd
+    for (s = base_server; s; s = s->next) {
bdaebd
+        dav_fs_server_conf *conf;
bdaebd
+
bdaebd
+        conf = ap_get_module_config(s->module_config, &dav_fs_module);
bdaebd
+
bdaebd
+        if (!conf->lockdb_path) {
bdaebd
+            conf->lockdb_path = ap_state_dir_relative(p, DEFAULT_DAV_LOCKDB);
bdaebd
+        }
bdaebd
+    }
bdaebd
+
bdaebd
+    return OK;
bdaebd
+}
bdaebd
+
bdaebd
 /*
bdaebd
  * Command handler for the DAVLockDB directive, which is TAKE1
bdaebd
  */
bdaebd
@@ -87,6 +109,8 @@ static const command_rec dav_fs_cmds[] =
bdaebd
 
bdaebd
 static void register_hooks(apr_pool_t *p)
bdaebd
 {
bdaebd
+    ap_hook_post_config(dav_fs_post_config, NULL, NULL, APR_HOOK_MIDDLE);
bdaebd
+
bdaebd
     dav_hook_gather_propsets(dav_fs_gather_propsets, NULL, NULL,
bdaebd
                              APR_HOOK_MIDDLE);
bdaebd
     dav_hook_find_liveprop(dav_fs_find_liveprop, NULL, NULL, APR_HOOK_MIDDLE);
bdaebd
diff --git a/modules/md/mod_md_config.c b/modules/md/mod_md_config.c
bdaebd
index 336a21b..4d50e26 100644
bdaebd
--- a/modules/md/mod_md_config.c
bdaebd
+++ b/modules/md/mod_md_config.c
bdaebd
@@ -54,10 +54,18 @@
bdaebd
 
bdaebd
 #define DEF_VAL     (-1)
bdaebd
 
bdaebd
+#ifndef MD_DEFAULT_BASE_DIR
bdaebd
+#define MD_DEFAULT_BASE_DIR "md"
bdaebd
+#endif
bdaebd
+
bdaebd
 /* Default settings for the global conf */
bdaebd
 static md_mod_conf_t defmc = {
bdaebd
     NULL,
bdaebd
-    "md",
bdaebd
+#if 1
bdaebd
+    NULL, /* apply default state-dir-relative */
bdaebd
+#else
bdaebd
+    MD_DEFAULT_BASE_DIR,
bdaebd
+#endif
bdaebd
     NULL,
bdaebd
     NULL,
bdaebd
     80,
bdaebd
@@ -864,6 +872,12 @@ apr_status_t md_config_post_config(server_rec *s, apr_pool_t *p)
bdaebd
     if (mc->hsts_max_age > 0) {
bdaebd
         mc->hsts_header = apr_psprintf(p, "max-age=%d", mc->hsts_max_age);
bdaebd
     }
bdaebd
+
bdaebd
+#if 1
bdaebd
+    if (mc->base_dir == NULL) {
bdaebd
+        mc->base_dir = ap_state_dir_relative(p, MD_DEFAULT_BASE_DIR);
bdaebd
+    }
bdaebd
+#endif
bdaebd
     
bdaebd
     return APR_SUCCESS;
bdaebd
 }
bdaebd
diff --git a/server/core.c b/server/core.c
bdaebd
index bbe52e0..b5ab429 100644
bdaebd
--- a/server/core.c
bdaebd
+++ b/server/core.c
bdaebd
@@ -133,6 +133,8 @@ AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP;
bdaebd
 AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN;
bdaebd
 AP_DECLARE_DATA int ap_config_generation = 0;
bdaebd
 
bdaebd
+static const char *core_state_dir;
bdaebd
+
bdaebd
 static void *create_core_dir_config(apr_pool_t *a, char *dir)
bdaebd
 {
bdaebd
     core_dir_config *conf;
bdaebd
@@ -1411,12 +1413,15 @@ AP_DECLARE(const char *) ap_resolve_env(apr_pool_t *p, const char * word)
bdaebd
     return res_buf;
bdaebd
 }
bdaebd
 
bdaebd
-static int reset_config_defines(void *dummy)
bdaebd
+/* pconf cleanup - clear global variables set from config here. */
bdaebd
+static apr_status_t reset_config(void *dummy)
bdaebd
 {
bdaebd
     ap_server_config_defines = saved_server_config_defines;
bdaebd
     saved_server_config_defines = NULL;
bdaebd
     server_config_defined_vars = NULL;
bdaebd
-    return OK;
bdaebd
+    core_state_dir = NULL;
bdaebd
+
bdaebd
+    return APR_SUCCESS;
bdaebd
 }
bdaebd
 
bdaebd
 /*
bdaebd
@@ -3108,6 +3113,24 @@ static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg)
bdaebd
     return NULL;
bdaebd
 }
bdaebd
 
bdaebd
+static const char *set_state_dir(cmd_parms *cmd, void *dummy, const char *arg)
bdaebd
+{
bdaebd
+    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
bdaebd
+
bdaebd
+    if (err != NULL) {
bdaebd
+        return err;
bdaebd
+    }
bdaebd
+
bdaebd
+    if ((apr_filepath_merge((char**)&core_state_dir, NULL,
bdaebd
+                            ap_server_root_relative(cmd->temp_pool, arg),
bdaebd
+                            APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS)
bdaebd
+        || !ap_is_directory(cmd->temp_pool, core_state_dir)) {
bdaebd
+        return "DefaultStateDir must be a valid directory, absolute or relative to ServerRoot";
bdaebd
+    }
bdaebd
+
bdaebd
+    return NULL;
bdaebd
+}
bdaebd
+
bdaebd
 static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg)
bdaebd
 {
bdaebd
     const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT);
bdaebd
@@ -4409,6 +4432,8 @@ AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ,
bdaebd
   "Common directory of server-related files (logs, confs, etc.)"),
bdaebd
 AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ,
bdaebd
   "Common directory for run-time files (shared memory, locks, etc.)"),
bdaebd
+AP_INIT_TAKE1("DefaultStateDir", set_state_dir, NULL, RSRC_CONF | EXEC_ON_READ,
bdaebd
+  "Common directory for persistent state (databases, long-lived caches, etc.)"),
bdaebd
 AP_INIT_TAKE1("ErrorLog", set_server_string_slot,
bdaebd
   (void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF,
bdaebd
   "The filename of the error log"),
bdaebd
@@ -4932,8 +4957,7 @@ static int core_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptem
bdaebd
 
bdaebd
     if (!saved_server_config_defines)
bdaebd
         init_config_defines(pconf);
bdaebd
-    apr_pool_cleanup_register(pconf, NULL, reset_config_defines,
bdaebd
-                              apr_pool_cleanup_null);
bdaebd
+    apr_pool_cleanup_register(pconf, NULL, reset_config, apr_pool_cleanup_null);
bdaebd
 
bdaebd
     ap_regcomp_set_default_cflags(AP_REG_DOLLAR_ENDONLY);
bdaebd
 
bdaebd
@@ -5202,6 +5226,27 @@ AP_DECLARE(int) ap_state_query(int query)
bdaebd
     }
bdaebd
 }
bdaebd
 
bdaebd
+AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *file)
bdaebd
+{
bdaebd
+    char *newpath = NULL;
bdaebd
+    apr_status_t rv;
bdaebd
+    const char *state_dir;
bdaebd
+
bdaebd
+    state_dir = core_state_dir
bdaebd
+        ? core_state_dir
bdaebd
+        : ap_server_root_relative(p, DEFAULT_REL_STATEDIR);
bdaebd
+
bdaebd
+    rv = apr_filepath_merge(&newpath, state_dir, file, APR_FILEPATH_TRUENAME, p);
bdaebd
+    if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv)
bdaebd
+                                      || APR_STATUS_IS_ENOENT(rv)
bdaebd
+                                      || APR_STATUS_IS_ENOTDIR(rv))) {
bdaebd
+        return newpath;
bdaebd
+    }
bdaebd
+    else {
bdaebd
+        return NULL;
bdaebd
+    }
bdaebd
+}
bdaebd
+
bdaebd
 static apr_random_t *rng = NULL;
bdaebd
 #if APR_HAS_THREADS
bdaebd
 static apr_thread_mutex_t *rng_mutex = NULL;