[Asterisk-code-review] Introduce astcachedir, to be used for temporary bucket files (asterisk[18])

George Joseph asteriskteam at digium.com
Wed Dec 9 13:06:06 CST 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15160 )

Change subject: Introduce astcachedir, to be used for temporary bucket files
......................................................................

Introduce astcachedir, to be used for temporary bucket files

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
---
M Makefile
M build_tools/install_subst
M build_tools/make_defaults_h
M build_tools/mkpkgconfig
M configs/samples/asterisk.conf.sample
M configure
M configure.ac
A doc/CHANGES-staging/media_cache_cachedir.txt
M include/asterisk/paths.h
M main/bucket.c
M main/options.c
M main/pbx_variables.c
M makeopts.in
13 files changed, 31 insertions(+), 4 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/Makefile b/Makefile
index dd1feed..2a45065 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,7 @@
 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 @@
 
 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 @@
 	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)|' \
diff --git a/build_tools/install_subst b/build_tools/install_subst
index 5b5407a..9f67a80 100755
--- a/build_tools/install_subst
+++ b/build_tools/install_subst
@@ -26,6 +26,7 @@
 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 4a9fb55..acda651 100755
--- a/build_tools/make_defaults_h
+++ b/build_tools/make_defaults_h
@@ -7,6 +7,7 @@
  */
 #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 9d29b9e..12dbd4e 100755
--- a/build_tools/mkpkgconfig
+++ b/build_tools/mkpkgconfig
@@ -32,6 +32,7 @@
 cat <<EOF > "$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 3c1a403..efb3386 100644
--- a/configs/samples/asterisk.conf.sample
+++ b/configs/samples/asterisk.conf.sample
@@ -1,4 +1,5 @@
 [directories](!)
+astcachedir => /tmp
 astetcdir => /etc/asterisk
 astmoddir => /usr/lib/asterisk/modules
 astvarlibdir => /var/lib/asterisk
diff --git a/configure b/configure
index b424bd8..98fb6cd 100755
--- a/configure
+++ b/configure
@@ -1295,6 +1295,7 @@
 BUILD_VENDOR
 BUILD_CPU
 BUILD_PLATFORM
+astcachedir
 astvarrundir
 astlogdir
 astspooldir
@@ -4660,6 +4661,7 @@
 
 # System default paths
 astsbindir='${sbindir}'
+astcachedir='/tmp'
 astetcdir='${sysconfdir}/asterisk'
 astheaderdir='${includedir}/asterisk'
 astlibdir='${libdir}'
@@ -4728,6 +4730,7 @@
      ;;
      solaris*)
      if test ${prefix} = 'NONE'; then
+        astcachedir=/tmp
         astetcdir=/var/etc/asterisk
         astsbindir=/opt/asterisk/sbin
         astlibdir=/opt/asterisk/lib
diff --git a/configure.ac b/configure.ac
index 88309d0..e842a0c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@
 
 # 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 @@
      ;;
      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
index 0000000..a57d151
--- /dev/null
+++ b/doc/CHANGES-staging/media_cache_cachedir.txt
@@ -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.
diff --git a/include/asterisk/paths.h b/include/asterisk/paths.h
index de28c75..e6f8c9f 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 8f6eafa..3e86996 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 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 62f2c2d..f46aa74 100644
--- a/main/options.c
+++ b/main/options.c
@@ -98,6 +98,7 @@
 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 @@
 };
 
 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 @@
 	.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 @@
 	}
 
 	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 e3c26f8..91b5bbb 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -327,6 +327,8 @@
 			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 0d69fc8..27a5bdc 100644
--- a/makeopts.in
+++ b/makeopts.in
@@ -97,6 +97,7 @@
 ASTMANDIR = @astmandir@
 astvarlibdir = @astvarlibdir@
 ASTVARLIBDIR = @astvarlibdir@
+ASTCACHEDIR = @astcachedir@
 ASTDATADIR = @astdatadir@
 ASTDBDIR = @astdbdir@
 ASTKEYDIR = @astkeydir@

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15160
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: Ic54e95199405abacd9e509cef5f08fa14c510b5d
Gerrit-Change-Number: 15160
Gerrit-PatchSet: 4
Gerrit-Owner: lvl <digium at lvlconsultancy.nl>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201209/13f561ec/attachment-0001.html>


More information about the asterisk-code-review mailing list