diff --git a/Makefile b/Makefile index dd1feedec6..4a750bd6f6 100644 --- 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)|' \ @@ -1041,6 +1043,7 @@ uninstall-all: _uninstall uninstall-headers rm -rf "$(DESTDIR)$(ASTSPOOLDIR)" rm -rf "$(DESTDIR)$(ASTETCDIR)" rm -rf "$(DESTDIR)$(ASTLOGDIR)" + rm -rf "$(DESTDIR)$(ASTCACHEDIR)" menuconfig: menuselect diff --git a/build_tools/install_subst b/build_tools/install_subst index 5b5407aa8c..9f67a80cbd 100755 --- a/build_tools/install_subst +++ b/build_tools/install_subst @@ -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" \ diff --git a/build_tools/make_defaults_h b/build_tools/make_defaults_h index 4a9fb55213..acda6510ac 100755 --- a/build_tools/make_defaults_h +++ b/build_tools/make_defaults_h @@ -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}" diff --git a/build_tools/mkpkgconfig b/build_tools/mkpkgconfig index 9d29b9eca0..12dbd4e015 100755 --- a/build_tools/mkpkgconfig +++ b/build_tools/mkpkgconfig @@ -32,6 +32,7 @@ LOCAL_CFLAGS=`echo $CFLAGS | ${EXTREGEX} 's/-pipe\s*//g' | ${EXTREGEX} 's/-[Wmp] cat < "$PPATH/asterisk.pc" install_prefix=$INSTALL_PREFIX version_number=$ASTERISKVERSIONNUM +cachedir=$ASTCACHEDIR etcdir=$ASTETCDIR libdir=$ASTLIBDIR varlibdir=$ASTVARLIBDIR diff --git a/configs/samples/asterisk.conf.sample b/configs/samples/asterisk.conf.sample index 3c1a4036a7..b2a4da88d5 100644 --- a/configs/samples/asterisk.conf.sample +++ b/configs/samples/asterisk.conf.sample @@ -1,4 +1,5 @@ [directories](!) +astcachedir => /var/cache/asterisk astetcdir => /etc/asterisk astmoddir => /usr/lib/asterisk/modules astvarlibdir => /var/lib/asterisk diff --git a/configure b/configure index b424bd8b66..d5e3a6a937 100755 --- 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='${localstatedir}/cache/asterisk' 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=/var/cache/asterisk astetcdir=/var/etc/asterisk astsbindir=/opt/asterisk/sbin astlibdir=/opt/asterisk/lib diff --git a/configure.ac b/configure.ac index 88309d096a..64a0a5ace5 100644 --- a/configure.ac +++ b/configure.ac @@ -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], ['${localstatedir}/cache/asterisk'])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=/var/cache/asterisk 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 index 0000000000..e30543fb29 --- /dev/null +++ b/doc/CHANGES-staging/media_cache_cachedir.txt @@ -0,0 +1,9 @@ +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. + +The default location for astcachedir is now /var/cache/asterisk +instead of /tmp, please make sure to manually cleanup and/or +migrate the temporary files in /tmp after upgrading. diff --git a/include/asterisk/paths.h b/include/asterisk/paths.h index de28c7575e..e6f8c9fe4c 100644 --- a/include/asterisk/paths.h +++ b/include/asterisk/paths.h @@ -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; diff --git a/main/bucket.c b/main/bucket.c index 8f6eafad05..3e86996212 100644 --- a/main/bucket.c +++ b/main/bucket.c @@ -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) { diff --git a/main/options.c b/main/options.c index 62f2c2da1c..f46aa74ccc 100644 --- a/main/options.c +++ b/main/options.c @@ -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)); diff --git a/main/pbx_variables.c b/main/pbx_variables.c index e3c26f889e..91b5bbb2b4 100644 --- a/main/pbx_variables.c +++ b/main/pbx_variables.c @@ -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")) { diff --git a/makeopts.in b/makeopts.in index 0d69fc8db3..27a5bdc15b 100644 --- a/makeopts.in +++ b/makeopts.in @@ -97,6 +97,7 @@ ASTMODDIR = @astmoddir@ ASTMANDIR = @astmandir@ astvarlibdir = @astvarlibdir@ ASTVARLIBDIR = @astvarlibdir@ +ASTCACHEDIR = @astcachedir@ ASTDATADIR = @astdatadir@ ASTDBDIR = @astdbdir@ ASTKEYDIR = @astkeydir@ diff --git a/tests/CI/installAsterisk.sh b/tests/CI/installAsterisk.sh index d84bf3e46f..00866d11ca 100755 --- a/tests/CI/installAsterisk.sh +++ b/tests/CI/installAsterisk.sh @@ -24,6 +24,7 @@ fi set +e if [ x"$USER_GROUP" != x ] ; then + chown -R $USER_GROUP $DESTDIR/var/cache/asterisk chown -R $USER_GROUP $DESTDIR/var/lib/asterisk chown -R $USER_GROUP $DESTDIR/var/spool/asterisk chown -R $USER_GROUP $DESTDIR/var/log/asterisk