summaryrefslogtreecommitdiff
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
authorSean Bright <sean.bright@gmail.com>2017-03-27 09:58:17 -0400
committerSean Bright <sean.bright@gmail.com>2017-03-27 08:00:50 -0600
commit0a8026072b0a559480701634454380e98efa0ba9 (patch)
tree4ddb88c4a7296c8a474109ac8bbf7e0ff3694564 /res/res_musiconhold.c
parent3e2cd7c5932399fe6ebcf73e324dc59a171fbe72 (diff)
res_musiconhold: Don't chdir() when scanning MoH files
There doesn't appear to be any reason that we are chdir'ing in moh_scan_files, and in the event of an Asterisk crash, the core files may not get written because we have changed into a read-only directory. ASTERISK-23996 #close Reported by: Walter Doekes Change-Id: Iac806dce01b3335963fbd62d4b4da9a65c614354
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c19
1 files changed, 1 insertions, 18 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 8fed3190a..b831083ce 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1114,16 +1114,13 @@ static int moh_scan_files(struct mohclass *class) {
DIR *files_DIR;
struct dirent *files_dirent;
char dir_path[PATH_MAX];
- char path[PATH_MAX];
char filepath[PATH_MAX];
char *ext;
struct stat statbuf;
int i;
if (class->dir[0] != '/') {
- ast_copy_string(dir_path, ast_config_AST_DATA_DIR, sizeof(dir_path));
- strncat(dir_path, "/", sizeof(dir_path) - 1);
- strncat(dir_path, class->dir, sizeof(dir_path) - 1);
+ snprintf(dir_path, sizeof(dir_path), "%s/%s", ast_config_AST_DATA_DIR, class->dir);
} else {
ast_copy_string(dir_path, class->dir, sizeof(dir_path));
}
@@ -1139,16 +1136,6 @@ static int moh_scan_files(struct mohclass *class) {
}
class->total_files = 0;
- if (!getcwd(path, sizeof(path))) {
- ast_log(LOG_WARNING, "getcwd() failed: %s\n", strerror(errno));
- closedir(files_DIR);
- return -1;
- }
- if (chdir(dir_path) < 0) {
- ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
- closedir(files_DIR);
- return -1;
- }
while ((files_dirent = readdir(files_DIR))) {
/* The file name must be at least long enough to have the file type extension */
if ((strlen(files_dirent->d_name) < 4))
@@ -1185,10 +1172,6 @@ static int moh_scan_files(struct mohclass *class) {
}
closedir(files_DIR);
- if (chdir(path) < 0) {
- ast_log(LOG_WARNING, "chdir() failed: %s\n", strerror(errno));
- return -1;
- }
if (ast_test_flag(class, MOH_SORTALPHA))
qsort(&class->filearray[0], class->total_files, sizeof(char *), moh_sort_compare);
return class->total_files;