diff options
-rw-r--r-- | Makefile.in | 1 | ||||
-rw-r--r-- | acinclude.m4 | 4 | ||||
-rw-r--r-- | config.layout | 15 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | include/ap_config_layout.h.in | 4 | ||||
-rw-r--r-- | include/ap_mmn.h | 3 | ||||
-rw-r--r-- | include/http_config.h | 8 | ||||
-rw-r--r-- | server/core.c | 44 |
8 files changed, 75 insertions, 6 deletions
diff --git a/Makefile.in b/Makefile.in index 1bd6e779e2..80683d9a49 100644 --- a/Makefile.in +++ b/Makefile.in @@ -218,6 +218,7 @@ install-cgi: install-other: @test -d $(DESTDIR)$(logfiledir) || $(MKINSTALLDIRS) $(DESTDIR)$(logfiledir) @test -d $(DESTDIR)$(runtimedir) || $(MKINSTALLDIRS) $(DESTDIR)$(runtimedir) + @test -d $(DESTDIR)$(statedir) || $(MKINSTALLDIRS) $(DESTDIR)$(statedir) @for ext in dll x; do \ file=apachecore.$$ext; \ if test -f $$file; then \ diff --git a/acinclude.m4 b/acinclude.m4 index 269636f1fa..ff1b642708 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -45,7 +45,7 @@ AC_DEFUN([APACHE_GEN_CONFIG_VARS],[ APACHE_SUBST(installbuilddir) APACHE_SUBST(runtimedir) APACHE_SUBST(proxycachedir) - APACHE_SUBST(davlockdb) + APACHE_SUBST(statedir) APACHE_SUBST(other_targets) APACHE_SUBST(progname) APACHE_SUBST(prefix) @@ -876,7 +876,7 @@ AC_DEFUN([APACHE_EXPORT_ARGUMENTS],[ APACHE_SUBST_EXPANDED_ARG(runtimedir) APACHE_SUBST_EXPANDED_ARG(logfiledir) APACHE_SUBST_EXPANDED_ARG(proxycachedir) - APACHE_SUBST_EXPANDED_ARG(davlockdb) + APACHE_SUBST_EXPANDED_ARG(statedir) ]) dnl diff --git a/config.layout b/config.layout index 8579587297..71c046c050 100644 --- a/config.layout +++ b/config.layout @@ -29,6 +29,7 @@ includedir: ${prefix}/include localstatedir: ${prefix} runtimedir: ${localstatedir}/logs + statedir: ${localstatedir}/state logfiledir: ${localstatedir}/logs proxycachedir: ${localstatedir}/proxy </Layout> @@ -54,6 +55,7 @@ includedir: ${prefix}/include+ localstatedir: ${prefix}/var+ runtimedir: ${localstatedir}/run + statedir: ${localstatedir}/state logfiledir: ${localstatedir}/log proxycachedir: ${localstatedir}/proxy </Layout> @@ -78,6 +80,7 @@ includedir: /System/Library/Frameworks/Apache.framework/Versions/2.0/Headers localstatedir: /var runtimedir: ${prefix}/Logs + statedir: ${prefix}/State logfiledir: ${prefix}/Logs proxycachedir: ${prefix}/ProxyCache </Layout> @@ -102,6 +105,7 @@ includedir: ${prefix}/include+ localstatedir: /var runtimedir: ${localstatedir}/run + statedir: ${localstatedir}/state logfiledir: ${localstatedir}/log+ proxycachedir: ${runtimedir}/proxy </Layout> @@ -126,6 +130,7 @@ includedir: ${prefix}/include/apache localstatedir: /var runtimedir: ${localstatedir}/run + statedir: ${localstatedir}/lib/httpd logfiledir: ${localstatedir}/log/httpd proxycachedir: ${localstatedir}/cache/httpd </Layout> @@ -151,6 +156,7 @@ includedir: ${prefix}/include/httpd runtimedir: /run/httpd logfiledir: ${localstatedir}/log/httpd + statedir: ${localstatedir}/lib/httpd proxycachedir: ${localstatedir}/cache/httpd/proxy </Layout> @@ -175,6 +181,7 @@ localstatedir: /var${prefix} runtimedir: ${localstatedir}/run logfiledir: ${localstatedir}/logs + statedir: ${localstatedir}/state proxycachedir: ${localstatedir}/proxy </Layout> @@ -197,6 +204,7 @@ cgidir: ${datadir}/cgi-bin includedir: ${prefix}/include/apache localstatedir: /var/lib/httpd + statedir: ${localstatedir} runtimedir: /var/run logfiledir: /var/log/httpd proxycachedir: /var/cache/httpd @@ -223,6 +231,7 @@ localstatedir: /var runtimedir: ${localstatedir}/run logfiledir: ${localstatedir}/log/httpd + statedir: ${prefix}/state proxycachedir: ${localstatedir}/proxy </Layout> @@ -246,6 +255,7 @@ includedir: ${exec_prefix}/include localstatedir: ${prefix} runtimedir: /var/run + statedir: ${datadir}/state logfiledir: ${datadir}/logs proxycachedir: ${datadir}/proxy </Layout> @@ -271,6 +281,7 @@ localstatedir: ${prefix} runtimedir: ${prefix}/logs logfiledir: ${prefix}/logs + statedir: ${prefix}/state proxycachedir: ${prefix}/proxy </Layout> @@ -315,6 +326,7 @@ cgidir: ${prefix}/usr/lib/cgi-bin includedir: ${exec_prefix}/include/apache2 localstatedir: ${prefix}/var/lock/apache2 + statedir: ${prefix}/var/lib/apache2 runtimedir: ${prefix}/var/run/apache2 logfiledir: ${prefix}/var/log/apache2 proxycachedir: ${prefix}/var/cache/apache2/proxy @@ -343,6 +355,7 @@ manualdir: ${datadir}/manual cgidir: ${datadir}/cgi-bin runtimedir: ${localstatedir}/run + runtimedir: ${localstatedir}/lib/httpd logfiledir: ${localstatedir}/log/httpd proxycachedir: ${localstatedir}/cache/httpd/cache-root </Layout> @@ -366,6 +379,7 @@ manualdir: ${prefix}/manual includedir: ${prefix}/include localstatedir: /var/httpd + statedir: ${localstatedir}/state runtimedir: ${localstatedir}/run logfiledir: ${localstatedir}/logs proxycachedir: ${localstatedir}/proxy @@ -391,6 +405,7 @@ includedir: ${prefix}/include/httpd localstatedir: /var runtimedir: ${localstatedir}/run/httpd + statedir: ${localstatedir}/lib/httpd logfiledir: ${localstatedir}/log/httpd proxycachedir: ${localstatedir}/cache/httpd </Layout> diff --git a/configure.in b/configure.in index 22b9d596e8..b20aad03f6 100644 --- a/configure.in +++ b/configure.in @@ -41,7 +41,7 @@ dnl Something seems broken here. AC_PREFIX_DEFAULT(/usr/local/apache2) dnl Get the layout here, so we can pass the required variables to apr -APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir]) +APR_ENABLE_LAYOUT(Apache, [errordir iconsdir htdocsdir cgidir statedir]) dnl reparse the configure arguments. APR_PARSE_ARGUMENTS diff --git a/include/ap_config_layout.h.in b/include/ap_config_layout.h.in index cda6a1130e..e076f41acc 100644 --- a/include/ap_config_layout.h.in +++ b/include/ap_config_layout.h.in @@ -60,7 +60,7 @@ #define DEFAULT_REL_LOGFILEDIR "@rel_logfiledir@" #define DEFAULT_EXP_PROXYCACHEDIR "@exp_proxycachedir@" #define DEFAULT_REL_PROXYCACHEDIR "@rel_proxycachedir@" -#define DEFAULT_EXP_DAVLOCKDB "@exp_davlockdb@" -#define DEFAULT_REL_DAVLOCKDB "@rel_davlockdb@" +#define DEFAULT_EXP_STATEDIR "@exp_statedir@" +#define DEFAULT_REL_STATEDIR "@rel_statedir@" #endif /* AP_CONFIG_LAYOUT_H */ diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 090211d9a7..235e70d40e 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -607,6 +607,7 @@ * in ap_filter_t replace pending/bb/deferred_pool * fields by struct ap_filter_private *priv * 20180906.1 (2.5.1-dev) Don't export ap_filter_recycle() anymore + * 20180906.2 (2.5.1-dev) Add ap_state_dir_relative() */ #define MODULE_MAGIC_COOKIE 0x41503235UL /* "AP25" */ @@ -614,7 +615,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20180906 #endif -#define MODULE_MAGIC_NUMBER_MINOR 1 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 2 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/http_config.h b/include/http_config.h index 996b358b07..f940f84f6a 100644 --- a/include/http_config.h +++ b/include/http_config.h @@ -760,6 +760,14 @@ AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname); */ AP_DECLARE(char *) ap_runtime_dir_relative(apr_pool_t *p, const char *fname); +/** + * Compute the name of a persistent state file (e.g. a database or + * long-lived cache) relative to the appropriate state directory. + * Absolute paths are returned as-is. The state directory is + * configured via the DefaultStateDir directive or at build time. + */ +AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *fname); + /* Finally, the hook for dynamically loading modules in... */ /** diff --git a/server/core.c b/server/core.c index 75e9c9c973..92245b3d64 100644 --- a/server/core.c +++ b/server/core.c @@ -148,6 +148,8 @@ AP_DECLARE_DATA int ap_main_state = AP_SQ_MS_INITIAL_STARTUP; AP_DECLARE_DATA int ap_run_mode = AP_SQ_RM_UNKNOWN; AP_DECLARE_DATA int ap_config_generation = 0; +static const char *core_state_dir; + typedef struct { apr_ipsubnet_t *subnet; struct ap_logconf log; @@ -3275,6 +3277,24 @@ static const char *set_runtime_dir(cmd_parms *cmd, void *dummy, const char *arg) return NULL; } +static const char *set_state_dir(cmd_parms *cmd, void *dummy, const char *arg) +{ + const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); + + if (err != NULL) { + return err; + } + + if ((apr_filepath_merge((char**)&core_state_dir, NULL, + ap_server_root_relative(cmd->temp_pool, arg), + APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) + || !ap_is_directory(cmd->temp_pool, core_state_dir)) { + return "DefaultStateDir must be a valid directory, absolute or relative to ServerRoot"; + } + + return NULL; +} + static const char *set_timeout(cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_CONTEXT); @@ -4724,6 +4744,8 @@ AP_INIT_TAKE1("ServerRoot", set_server_root, NULL, RSRC_CONF | EXEC_ON_READ, "Common directory of server-related files (logs, confs, etc.)"), AP_INIT_TAKE1("DefaultRuntimeDir", set_runtime_dir, NULL, RSRC_CONF | EXEC_ON_READ, "Common directory for run-time files (shared memory, locks, etc.)"), +AP_INIT_TAKE1("DefaultStateDir", set_state_dir, NULL, RSRC_CONF | EXEC_ON_READ, + "Common directory for persistent state (databases, long-lived caches, etc.)"), AP_INIT_TAKE12("ErrorLog", set_errorlog, (void *)APR_OFFSETOF(server_rec, error_fname), RSRC_CONF, "The filename of the error log"), @@ -5557,6 +5579,28 @@ AP_DECLARE(int) ap_state_query(int query) } } +AP_DECLARE(char *) ap_state_dir_relative(apr_pool_t *p, const char *file) +{ + char *newpath = NULL; + apr_status_t rv; + const char *state_dir; + + state_dir = core_state_dir + ? core_state_dir + : ap_server_root_relative(p, DEFAULT_REL_STATEDIR); + + rv = apr_filepath_merge(&newpath, state_dir, file, APR_FILEPATH_TRUENAME, p); + if (newpath && (rv == APR_SUCCESS || APR_STATUS_IS_EPATHWILD(rv) + || APR_STATUS_IS_ENOENT(rv) + || APR_STATUS_IS_ENOTDIR(rv))) { + return newpath; + } + else { + return NULL; + } +} + + #if !USE_APR_CRYPTO_PRNG static apr_random_t *rng = NULL; #if APR_HAS_THREADS |