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

lvl asteriskteam at digium.com
Thu Oct 29 06:50:49 CDT 2020


lvl has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15076 )


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
M include/asterisk/paths.h
M main/bucket.c
M main/options.c
M main/pbx_variables.c
M makeopts.in
12 files changed, 25 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/76/15076/1

diff --git a/Makefile b/Makefile
index fd1c1db..3f2f35d 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 f6e38b6..cd3c7c1 100755
--- a/configure
+++ b/configure
@@ -1287,6 +1287,7 @@
 BUILD_VENDOR
 BUILD_CPU
 BUILD_PLATFORM
+astcachedir
 astvarrundir
 astlogdir
 astspooldir
@@ -4652,6 +4653,7 @@
 
 # System default paths
 astsbindir='${sbindir}'
+astcachedir='/tmp'
 astetcdir='${sysconfdir}/asterisk'
 astheaderdir='${includedir}/asterisk'
 astlibdir='${libdir}'
@@ -4720,6 +4722,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 a9302b7..62d02ec 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/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 fc68c6d..593b908 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/+/15076
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ic54e95199405abacd9e509cef5f08fa14c510b5d
Gerrit-Change-Number: 15076
Gerrit-PatchSet: 1
Gerrit-Owner: lvl <digium at lvlconsultancy.nl>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201029/02a94318/attachment-0001.html>


More information about the asterisk-code-review mailing list