aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-31 21:00:24 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-01-31 21:00:24 +0000
commit1552ee776cd8de959b6d9f07677644a5344fac5c (patch)
tree901d604dbf18e94df3f445791def52c493087fe4 /res
parentbf33319d6d759ebe284281d5e3cf2f99dc13ff06 (diff)
1. Prevent the addition of an extra '/' to the beginning of an absolute pathname.
2. If ast_monitor_change_fname is called and the new filename is the same as the old, then exit early and don't set the filename_changed field in the monitor structure. Setting it in this case was causing ast_monitor_stop to erroneously delete them. (closes issue #11741) Reported by: garlew Tested by: putnopvut git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@101531 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_monitor.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/res/res_monitor.c b/res/res_monitor.c
index 26bee41af..4baa1580d 100644
--- a/res/res_monitor.c
+++ b/res/res_monitor.c
@@ -47,6 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/app.h"
#include "asterisk/utils.h"
#include "asterisk/config.h"
+#include "asterisk/options.h"
AST_MUTEX_DEFINE_STATIC(monitorlock);
@@ -156,6 +157,7 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
/* Determine file names */
if (!ast_strlen_zero(fname_base)) {
int directory = strchr(fname_base, '/') ? 1 : 0;
+ const char *absolute = *fname_base == '/' ? "" : "/";
/* try creating the directory just in case it doesn't exist */
if (directory) {
char *name = strdup(fname_base);
@@ -163,10 +165,10 @@ int ast_monitor_start( struct ast_channel *chan, const char *format_spec,
free(name);
ast_safe_system(tmp);
}
- snprintf(monitor->read_filename, FILENAME_MAX, "%s/%s-in",
- directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
- snprintf(monitor->write_filename, FILENAME_MAX, "%s/%s-out",
- directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
+ snprintf(monitor->read_filename, FILENAME_MAX, "%s%s%s-in",
+ directory ? "" : ast_config_AST_MONITOR_DIR, absolute, fname_base);
+ snprintf(monitor->write_filename, FILENAME_MAX, "%s%s%s-out",
+ directory ? "" : ast_config_AST_MONITOR_DIR, absolute, fname_base);
ast_copy_string(monitor->filename_base, fname_base, sizeof(monitor->filename_base));
} else {
ast_mutex_lock(&monitorlock);
@@ -300,6 +302,7 @@ int ast_monitor_stop(struct ast_channel *chan, int need_lock)
int directory = strchr(name, '/') ? 1 : 0;
char *dir = directory ? "" : ast_config_AST_MONITOR_DIR;
const char *execute, *execute_args;
+ const char *absolute = *name == '/' ? "" : "/";
/* Set the execute application */
execute = pbx_builtin_getvar_helper(chan, "MONITOR_EXEC");
@@ -317,9 +320,9 @@ int ast_monitor_stop(struct ast_channel *chan, int need_lock)
execute_args = "";
}
- snprintf(tmp, sizeof(tmp), "%s \"%s/%s-in.%s\" \"%s/%s-out.%s\" \"%s/%s.%s\" %s &", execute, dir, name, format, dir, name, format, dir, name, format,execute_args);
+ snprintf(tmp, sizeof(tmp), "%s \"%s%s%s-in.%s\" \"%s%s%s-out.%s\" \"%s%s%s.%s\" %s &", execute, dir, absolute, name, format, dir, absolute, name, format, dir, absolute, name, format,execute_args);
if (delfiles) {
- snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s/%s-\"* ) &",tmp, dir ,name); /* remove legs when done mixing */
+ snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s%s%s-\"* ) &",tmp, dir, absolute, name); /* remove legs when done mixing */
ast_copy_string(tmp, tmp2, sizeof(tmp));
}
ast_log(LOG_DEBUG,"monitor executing %s\n",tmp);
@@ -373,6 +376,18 @@ int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, i
if (chan->monitor) {
int directory = strchr(fname_base, '/') ? 1 : 0;
+ const char *absolute = *fname_base == '/' ? "" : "/";
+ char tmpstring[sizeof(chan->monitor->filename_base)] = "";
+
+ /* before continuing, see if we're trying to rename the file to itself... */
+ snprintf(tmpstring, sizeof(tmpstring), "%s%s%s", directory ? "" : ast_config_AST_MONITOR_DIR, absolute, fname_base);
+ if (!strcmp(tmpstring, chan->monitor->filename_base)) {
+ if (option_debug > 2)
+ ast_log(LOG_DEBUG, "No need to rename monitor filename to itself\n");
+ UNLOCK_IF_NEEDED(chan, need_lock);
+ return 0;
+ }
+
/* try creating the directory just in case it doesn't exist */
if (directory) {
char *name = strdup(fname_base);
@@ -381,7 +396,7 @@ int ast_monitor_change_fname(struct ast_channel *chan, const char *fname_base, i
ast_safe_system(tmp);
}
- snprintf(chan->monitor->filename_base, FILENAME_MAX, "%s/%s", directory ? "" : ast_config_AST_MONITOR_DIR, fname_base);
+ ast_copy_string(chan->monitor->filename_base, tmpstring, sizeof(chan->monitor->filename_base));
chan->monitor->filename_changed = 1;
} else {
ast_log(LOG_WARNING, "Cannot change monitor filename of channel %s to %s, monitoring not started\n", chan->name, fname_base);