Author: Lott Caskey The patch adds the 'astsounddir' option to /etc/asterisk/asterisk.conf. This allows you to override Asterisk's sound directory without needing to make symlinks. A practical application of this would be to load the contents of /var/lib/asterisk/sounds into a tmpfs or ramdisk mount. Asterisk will then read the files directly from memory (provided tmpfs hasn't swapped) instead of a calling out to disk for every file. Index: build_tools/make_defaults_h =================================================================== --- build_tools/make_defaults_h (revision 321560) +++ build_tools/make_defaults_h (working copy) @@ -21,6 +21,7 @@ #define DEFAULT_DATA_DIR "${INSTALL_PATH}${ASTDATADIR}" #define DEFAULT_KEY_DIR "${INSTALL_PATH}${ASTDATADIR}/keys" +#define DEFAULT_SOUND_DIR "${INSTALL_PATH}${ASTDATADIR}/sounds" #define DEFAULT_SPOOL_DIR "${INSTALL_PATH}${ASTSPOOLDIR}" #define DEFAULT_TMP_DIR "${INSTALL_PATH}${ASTSPOOLDIR}/tmp" Index: apps/app_voicemail.c =================================================================== --- apps/app_voicemail.c (revision 321560) +++ apps/app_voicemail.c (working copy) @@ -12439,7 +12439,7 @@ ast_log(AST_LOG_WARNING, "Failed to make test directory\n"); goto exit_vmsayname_test; } - snprintf(dir, sizeof(dir), "%s/sounds/beep.gsm", ast_config_AST_VAR_DIR); + snprintf(dir, sizeof(dir), "%s/beep.gsm", ast_config_AST_SOUND_DIR); snprintf(dir2, sizeof(dir2), "%s%s/%s/greet.gsm", VM_SPOOL_DIR, TEST_CONTEXT, TEST_EXTENSION); /* we're not going to hear the sound anyway, just use a valid gsm audio file */ if ((res = symlink(dir, dir2))) { @@ -12541,7 +12541,7 @@ snprintf(tmp[i].txtfile, sizeof(tmp[i].txtfile), "%s.txt", tmp[i].file); if (ast_fileexists(origweasels, "gsm", "en") > 0) { - snprintf(syscmd, sizeof(syscmd), "cp \"%s/sounds/en/%s.gsm\" \"%s/%s/%s/%s/msg0000.gsm\"", ast_config_AST_DATA_DIR, origweasels, + snprintf(syscmd, sizeof(syscmd), "cp \"%s/en/%s.gsm\" \"%s/%s/%s/%s/msg0000.gsm\"", ast_config_AST_SOUND_DIR, origweasels, VM_SPOOL_DIR, testcontext, testmailbox, folders[i]); if ((syserr = ast_safe_system(syscmd))) { ast_test_status_update(test, "Unable to create test voicemail: %s\n", @@ -12677,8 +12677,8 @@ break; } - snprintf(attach, sizeof(attach), "%s/sounds/en/tt-weasels", ast_config_AST_VAR_DIR); - snprintf(attach2, sizeof(attach2), "%s/sounds/en/tt-somethingwrong", ast_config_AST_VAR_DIR); + snprintf(attach, sizeof(attach), "%s/en/tt-weasels", ast_config_AST_SOUND_DIR); + snprintf(attach2, sizeof(attach2), "%s/en/tt-somethingwrong", ast_config_AST_SOUND_DIR); if (!(vmu = find_user(&vmus, testcontext, testmailbox)) && !(vmu = find_or_create(testcontext, testmailbox))) { Index: apps/app_dial.c =================================================================== --- apps/app_dial.c (revision 321560) +++ apps/app_dial.c (working copy) @@ -1733,7 +1733,7 @@ call is actually dialed */ /* make sure the priv-callerintros dir actually exists */ - snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR); + snprintf(pa->privintro, sizeof(pa->privintro), "%s/priv-callerintros", ast_config_AST_SOUND_DIR); if ((res = ast_mkdir(pa->privintro, 0755))) { ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res)); return -1; Index: Makefile =================================================================== --- Makefile (revision 321560) +++ Makefile (working copy) @@ -129,6 +129,7 @@ ASTCONFPATH=$(ASTETCDIR)/asterisk.conf MODULES_DIR=$(ASTLIBDIR)/modules AGI_DIR=$(ASTDATADIR)/agi-bin +ASTSOUNDDIR=$(ASTDATADIR)/sounds # If you use Apache, you may determine by a grep 'DocumentRoot' of your httpd.conf file HTTP_DOCSDIR=/var/www/html Index: include/asterisk/paths.h =================================================================== --- include/asterisk/paths.h (revision 321560) +++ include/asterisk/paths.h (working copy) @@ -35,5 +35,6 @@ extern const char *ast_config_AST_RUN_GROUP; extern const char *ast_config_AST_RUN_USER; extern const char *ast_config_AST_SYSTEM_NAME; +extern const char *ast_config_AST_SOUND_DIR; #endif /* _ASTERISK_PATHS_H */ Index: main/app.c =================================================================== --- main/app.c (revision 321560) +++ main/app.c (working copy) @@ -540,7 +540,7 @@ if (filename[0] == '/') { ast_copy_string(tmpf, filename, sizeof(tmpf)); } else { - snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename); + snprintf(tmpf, sizeof(tmpf), "%s/%s", ast_config_AST_SOUND_DIR, filename); } if ((fd = open(tmpf, O_RDONLY)) < 0) { ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno)); Index: main/asterisk.c =================================================================== --- main/asterisk.c (revision 321560) +++ main/asterisk.c (working copy) @@ -239,6 +239,7 @@ char agi_dir[PATH_MAX]; char run_dir[PATH_MAX]; char key_dir[PATH_MAX]; + char sound_dir[PATH_MAX]; char config_file[PATH_MAX]; char db_path[PATH_MAX]; @@ -262,6 +263,7 @@ const char *ast_config_AST_AGI_DIR = cfg_paths.agi_dir; const char *ast_config_AST_KEY_DIR = cfg_paths.key_dir; const char *ast_config_AST_RUN_DIR = cfg_paths.run_dir; +const char *ast_config_AST_SOUND_DIR = cfg_paths.sound_dir; const char *ast_config_AST_DB = cfg_paths.db_path; const char *ast_config_AST_PID = cfg_paths.pid_path; @@ -2892,6 +2894,7 @@ ast_copy_string(cfg_paths.pid_path, DEFAULT_PID, sizeof(cfg_paths.pid_path)); ast_copy_string(cfg_paths.socket_path, DEFAULT_SOCKET, sizeof(cfg_paths.socket_path)); ast_copy_string(cfg_paths.run_dir, DEFAULT_RUN_DIR, sizeof(cfg_paths.run_dir)); + ast_copy_string(cfg_paths.sound_dir, DEFAULT_SOUND_DIR, sizeof(cfg_paths.sound_dir)); ast_set_default_eid(&ast_eid_default); @@ -2941,6 +2944,8 @@ ast_copy_string(cfg_paths.run_dir, v->value, sizeof(cfg_paths.run_dir)); } else if (!strcasecmp(v->name, "astmoddir")) { ast_copy_string(cfg_paths.module_dir, v->value, sizeof(cfg_paths.module_dir)); + } else if (!strcasecmp(v->name, "astsounddir")) { + ast_copy_string(cfg_paths.sound_dir, v->value, sizeof(cfg_paths.sound_dir)); } } Index: main/file.c =================================================================== --- main/file.c (revision 321560) +++ main/file.c (working copy) @@ -244,7 +244,7 @@ /*! * \brief construct a filename. Absolute pathnames are preserved, - * relative names are prefixed by the sounds/ directory. + * relative names are prefixed by the ast_config_AST_SOUND_DIR directory. * The wav49 suffix is replaced by 'WAV'. * Returns a malloc'ed string to be freed by the caller. */ @@ -261,8 +261,8 @@ fn = NULL; } } else { - if (asprintf(&fn, "%s/sounds/%s.%s", - ast_config_AST_DATA_DIR, filename, ext) < 0) { + if (asprintf(&fn, "%s/%s.%s", + ast_config_AST_SOUND_DIR, filename, ext) < 0) { ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); fn = NULL; }