[asterisk-commits] res musiconhold: Don't chdir() when scanning MoH files (asterisk[13])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Mar 29 08:15:01 CDT 2017
Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5325 )
Change subject: res_musiconhold: Don't chdir() when scanning MoH files
......................................................................
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
---
M res/res_musiconhold.c
1 file changed, 1 insertion(+), 18 deletions(-)
Approvals:
Kevin Harwell: Looks good to me, but someone else must approve
Anonymous Coward #1000019: Verified
Joshua Colp: Looks good to me, approved
Corey Farrell: Looks good to me, but someone else must approve
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 6b0f00a..2bc14aa 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -1075,16 +1075,13 @@
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));
}
@@ -1100,16 +1097,6 @@
}
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))
@@ -1146,10 +1133,6 @@
}
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;
--
To view, visit https://gerrit.asterisk.org/5325
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iac806dce01b3335963fbd62d4b4da9a65c614354
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
More information about the asterisk-commits
mailing list