]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Introduce astcachedir, to be used for temporary bucket files
authorlvl <digium@lvlconsultancy.nl>
Thu, 29 Oct 2020 11:25:27 +0000 (12:25 +0100)
committerGeorge Joseph <gjoseph@digium.com>
Wed, 9 Dec 2020 19:06:04 +0000 (13:06 -0600)
As described in the issue, /tmp is not a suitable location for a
large amount of cached media files, since most distributions make
/tmp a RAM-based tmpfs mount with limited capacity.

I opted for a location that can be configured separately, as opposed
to using a subdirectory of spooldir, given the different storage
profile (transient files vs files that might stay there indefinitely).

This commit just makes the cache directory configurable, but leaves
it at /tmp by default, to ensure backwards compatibility.

A future commit that only targets master could change the default
location to something more sensible such as /var/tmp/asterisk. At
that point, the cachedir could be created and cleaned up during
uninstall by the Makefile script.

ASTERISK-29143

Change-Id: Ic54e95199405abacd9e509cef5f08fa14c510b5d

13 files changed:
Makefile
build_tools/install_subst
build_tools/make_defaults_h
build_tools/mkpkgconfig
configs/samples/asterisk.conf.sample
configure
configure.ac
doc/CHANGES-staging/media_cache_cachedir.txt [new file with mode: 0644]
include/asterisk/paths.h
main/bucket.c
main/options.c
main/pbx_variables.c
makeopts.in

index dd1feedec6a9678d5a40ad6b128952637c73885c..2a450656c73dca9d2d04695127f3d5ccb0645ea7 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@ DESTDIR?=$(INSTALL_PATH)
 export DESTDIR
 
 export INSTALL_PATH       # Additional prefix for the following paths
+export ASTCACHEDIR
 export ASTETCDIR          # Path for config files
 export ASTVARRUNDIR
 export ASTSPOOLDIR
@@ -555,7 +556,7 @@ update:
 
 NEWHEADERS=$(notdir $(wildcard include/asterisk/*.h))
 OLDHEADERS=$(filter-out $(NEWHEADERS) $(notdir $(DESTDIR)$(ASTHEADERDIR)),$(notdir $(wildcard $(DESTDIR)$(ASTHEADERDIR)/*.h)))
-INSTALLDIRS="$(ASTLIBDIR)" "$(ASTMODDIR)" "$(ASTSBINDIR)" "$(ASTETCDIR)" "$(ASTVARRUNDIR)" \
+INSTALLDIRS="$(ASTLIBDIR)" "$(ASTMODDIR)" "$(ASTSBINDIR)" "$(ASTCACHEDIR)" "$(ASTETCDIR)" "$(ASTVARRUNDIR)" \
        "$(ASTSPOOLDIR)" "$(ASTSPOOLDIR)/dictate" "$(ASTSPOOLDIR)/meetme" \
        "$(ASTSPOOLDIR)/monitor" "$(ASTSPOOLDIR)/system" "$(ASTSPOOLDIR)/tmp" \
        "$(ASTSPOOLDIR)/voicemail" "$(ASTSPOOLDIR)/recording" \
@@ -779,7 +780,8 @@ define INSTALL_CONFIGS
        done ; \
        if [ "$(OVERWRITE)" = "y" ]; then \
                echo "Updating asterisk.conf" ; \
-               sed -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
+               sed -e 's|^astcachedir.*$$|astcachedir => $(ASTCACHEDIR)|' \
+                       -e 's|^astetcdir.*$$|astetcdir => $(ASTETCDIR)|' \
                        -e 's|^astmoddir.*$$|astmoddir => $(ASTMODDIR)|' \
                        -e 's|^astvarlibdir.*$$|astvarlibdir => $(ASTVARLIBDIR)|' \
                        -e 's|^astdbdir.*$$|astdbdir => $(ASTDBDIR)|' \
index 5b5407aa8c3ef8ea5c15aeb1ee8d8de3333e841e..9f67a80cbd0501054342a56ccb53ecf1ed7b8045 100755 (executable)
@@ -26,6 +26,7 @@ trap cleanup_tmp 0
 src="$1"
 dst="$2"
 sed <"$src" \
+       -e "s|__ASTERISK_CACHE_DIR__|$ASTCACHEDIR|g" \
        -e "s|__ASTERISK_DATA_DIR__|$ASTDATADIR|g" \
        -e "s|__ASTERISK_DB_DIR__|$ASTDBDIR|g" \
        -e "s|__ASTERISK_ETC_DIR__|$ASTETCDIR|g" \
index 4a9fb55213bd1d8b1a56563b7b0cbff77ac7dc02..acda6510ac9a219925011122c611c03f3bd39a3a 100755 (executable)
@@ -7,6 +7,7 @@ cat << END
  */
 #define DEFAULT_CONFIG_FILE "${INSTALL_PATH}${ASTCONFPATH}"
 
+#define DEFAULT_CACHE_DIR  "${INSTALL_PATH}${ASTCACHEDIR}"
 #define DEFAULT_CONFIG_DIR "${INSTALL_PATH}${ASTETCDIR}"
 #define DEFAULT_MODULE_DIR "${INSTALL_PATH}${ASTMODDIR}"
 #define DEFAULT_AGI_DIR    "${INSTALL_PATH}${AGI_DIR}"
index 9d29b9eca04d525eb8d37489f3ec28f49317fa3c..12dbd4e0159fe3cf9f3a1552ad9ae7839db45b89 100755 (executable)
@@ -32,6 +32,7 @@ LOCAL_CFLAGS=`echo $CFLAGS | ${EXTREGEX} 's/-pipe\s*//g' | ${EXTREGEX} 's/-[Wmp]
 cat <<EOF > "$PPATH/asterisk.pc"
 install_prefix=$INSTALL_PREFIX
 version_number=$ASTERISKVERSIONNUM
+cachedir=$ASTCACHEDIR
 etcdir=$ASTETCDIR
 libdir=$ASTLIBDIR
 varlibdir=$ASTVARLIBDIR
index 3c1a4036a7877d5e6e611abe16c6228b46df03c3..efb33862aea4fa343fb5d8dc0092d91f7d0513e4 100644 (file)
@@ -1,4 +1,5 @@
 [directories](!)
+astcachedir => /tmp
 astetcdir => /etc/asterisk
 astmoddir => /usr/lib/asterisk/modules
 astvarlibdir => /var/lib/asterisk
index b424bd8b66da682e0b2b0adf6fa589c95d1848a5..98fb6cdbfbf3b1b523b628f8514658cd8df4e9fd 100755 (executable)
--- a/configure
+++ b/configure
@@ -1295,6 +1295,7 @@ BUILD_OS
 BUILD_VENDOR
 BUILD_CPU
 BUILD_PLATFORM
+astcachedir
 astvarrundir
 astlogdir
 astspooldir
@@ -4660,6 +4661,7 @@ $as_echo "$ac_cv_safe_to_define___extensions__" >&6; }
 
 # System default paths
 astsbindir='${sbindir}'
+astcachedir='/tmp'
 astetcdir='${sysconfdir}/asterisk'
 astheaderdir='${includedir}/asterisk'
 astlibdir='${libdir}'
@@ -4728,6 +4730,7 @@ $as_echo "#define _DARWIN_UNLIMITED_SELECT 1" >>confdefs.h
      ;;
      solaris*)
      if test ${prefix} = 'NONE'; then
+        astcachedir=/tmp
         astetcdir=/var/etc/asterisk
         astsbindir=/opt/asterisk/sbin
         astlibdir=/opt/asterisk/lib
index 88309d096a06654520d36a35918bdc3b045d9748..e842a0c087483fe0d7dd9b7670f41d1d71ad4280 100644 (file)
@@ -34,6 +34,7 @@ AC_USE_SYSTEM_EXTENSIONS      dnl note- does not work on FreeBSD
 
 # System default paths
 AC_SUBST([astsbindir],        ['${sbindir}'])dnl
+AC_SUBST([astcachedir],       ['/tmp'])dnl
 AC_SUBST([astetcdir],         ['${sysconfdir}/asterisk'])dnl
 AC_SUBST([astheaderdir],      ['${includedir}/asterisk'])dnl
 AC_SUBST([astlibdir],         ['${libdir}'])dnl
@@ -98,6 +99,7 @@ case "${host_os}" in
      ;;
      solaris*)
      if test ${prefix} = 'NONE'; then
+        astcachedir=/tmp
         astetcdir=/var/etc/asterisk
         astsbindir=/opt/asterisk/sbin
         astlibdir=/opt/asterisk/lib
diff --git a/doc/CHANGES-staging/media_cache_cachedir.txt b/doc/CHANGES-staging/media_cache_cachedir.txt
new file mode 100644 (file)
index 0000000..a57d151
--- /dev/null
@@ -0,0 +1,6 @@
+Subject: Core
+
+The location where the media cache stores its temporary files
+is no longer hardcoded to /tmp but can now be configured separately
+via the astcachedir config variable in asterisk.conf. To retain
+backwards compatibility, the default location remains /tmp.
index de28c7575efe21ee7c507dbf0501bf09fcfabe6a..e6f8c9fe4c394fa1515ef3f963011f232f325a04 100644 (file)
@@ -18,6 +18,7 @@
 #ifndef _ASTERISK_PATHS_H
 #define _ASTERISK_PATHS_H
 
+extern const char *ast_config_AST_CACHE_DIR;
 extern const char *ast_config_AST_CONFIG_DIR;
 extern const char *ast_config_AST_CONFIG_FILE;
 extern const char *ast_config_AST_MODULE_DIR;
index 8f6eafad05b43ab45d647babe6346f0cddd22dc5..3e869962124d57149530b0160a403fd27df5b326 100644 (file)
@@ -73,6 +73,7 @@
 #include "asterisk/json.h"
 #include "asterisk/file.h"
 #include "asterisk/module.h"
+#include "asterisk/paths.h"
 
 /*! \brief Number of buckets for the container of schemes */
 #define SCHEME_BUCKETS 53
@@ -899,7 +900,7 @@ int ast_bucket_file_temporary_create(struct ast_bucket_file *file)
 {
        int fd;
 
-       ast_copy_string(file->path, "/tmp/bucket-XXXXXX", sizeof(file->path));
+       snprintf(file->path, sizeof(file->path), "%s/bucket-XXXXXX", ast_config_AST_CACHE_DIR);
 
        fd = mkstemp(file->path);
        if (fd < 0) {
index 62f2c2da1cd3b13b23c91d72c3d9bbe4e13c6ecb..f46aa74cccb9b0e9bc8b98d5fb30a2f01aa17d30 100644 (file)
@@ -98,6 +98,7 @@ char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR;
 char ast_defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE;
 
 struct _cfg_paths {
+       char cache_dir[PATH_MAX];
        char config_dir[PATH_MAX];
        char module_dir[PATH_MAX];
        char spool_dir[PATH_MAX];
@@ -125,6 +126,7 @@ struct _cfg_paths {
 };
 
 static struct _cfg_paths cfg_paths = {
+       .cache_dir = DEFAULT_CACHE_DIR,
        .config_dir = DEFAULT_CONFIG_DIR,
        .module_dir = DEFAULT_MODULE_DIR,
        .spool_dir = DEFAULT_SPOOL_DIR,
@@ -145,6 +147,7 @@ static struct _cfg_paths cfg_paths = {
        .ctl_file = "asterisk.ctl",
 };
 
+const char *ast_config_AST_CACHE_DIR   = cfg_paths.cache_dir;
 const char *ast_config_AST_CONFIG_DIR  = cfg_paths.config_dir;
 const char *ast_config_AST_CONFIG_FILE = cfg_paths.config_file;
 const char *ast_config_AST_MODULE_DIR  = cfg_paths.module_dir;
@@ -254,7 +257,9 @@ void load_asterisk_conf(void)
        }
 
        for (v = ast_variable_browse(cfg, "directories"); v; v = v->next) {
-               if (!strcasecmp(v->name, "astetcdir")) {
+               if (!strcasecmp(v->name, "astcachedir")) {
+                       ast_copy_string(cfg_paths.cache_dir, v->value, sizeof(cfg_paths.cache_dir));
+               } else if (!strcasecmp(v->name, "astetcdir")) {
                        ast_copy_string(cfg_paths.config_dir, v->value, sizeof(cfg_paths.config_dir));
                } else if (!strcasecmp(v->name, "astspooldir")) {
                        ast_copy_string(cfg_paths.spool_dir, v->value, sizeof(cfg_paths.spool_dir));
index e3c26f889e3ed1eb312a942b19201896ba6cb9bf..91b5bbb2b451a0cf38cb73e97e01d72f24968b51 100644 (file)
@@ -327,6 +327,8 @@ const char *ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, stru
                        s = ast_str_buffer(*str);
                } else if (!strcmp(var, "SYSTEMNAME")) {
                        s = ast_config_AST_SYSTEM_NAME;
+               } else if (!strcmp(var, "ASTCACHEDIR")) {
+                       s = ast_config_AST_CACHE_DIR;
                } else if (!strcmp(var, "ASTETCDIR")) {
                        s = ast_config_AST_CONFIG_DIR;
                } else if (!strcmp(var, "ASTMODDIR")) {
index 0d69fc8db390adcc8aacee14331b03404b0d83e9..27a5bdc15b24f21108199c618d873d3a1364383a 100644 (file)
@@ -97,6 +97,7 @@ ASTMODDIR = @astmoddir@
 ASTMANDIR = @astmandir@
 astvarlibdir = @astvarlibdir@
 ASTVARLIBDIR = @astvarlibdir@
+ASTCACHEDIR = @astcachedir@
 ASTDATADIR = @astdatadir@
 ASTDBDIR = @astdbdir@
 ASTKEYDIR = @astkeydir@