[asterisk-commits] mmichelson: trunk r101532 - in /trunk: ./ res/res_monitor.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 31 15:02:12 CST 2008


Author: mmichelson
Date: Thu Jan 31 15:02:12 2008
New Revision: 101532

URL: http://svn.digium.com/view/asterisk?view=rev&rev=101532
Log:
Merged revisions 101531 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r101531 | mmichelson | 2008-01-31 15:00:24 -0600 (Thu, 31 Jan 2008) | 10 lines

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


........

Modified:
    trunk/   (props changed)
    trunk/res/res_monitor.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/res/res_monitor.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_monitor.c?view=diff&rev=101532&r1=101531&r2=101532
==============================================================================
--- trunk/res/res_monitor.c (original)
+++ trunk/res/res_monitor.c Thu Jan 31 15:02:12 2008
@@ -42,6 +42,7 @@
 #include "asterisk/app.h"
 #include "asterisk/utils.h"
 #include "asterisk/config.h"
+#include "asterisk/options.h"
 
 AST_MUTEX_DEFINE_STATIC(monitorlock);
 
@@ -164,15 +165,16 @@
 		/* 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 = ast_strdupa(fname_base);
 				ast_mkdir(dirname(name), 0777);
 			}
-			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);
@@ -327,6 +329,7 @@
 			int directory = strchr(name, '/') ? 1 : 0;
 			const 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");
@@ -344,9 +347,9 @@
 				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_debug(1,"monitor executing %s\n",tmp);
@@ -415,13 +418,25 @@
 
 	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 = ast_strdupa(fname_base);
 			ast_mkdir(dirname(name), 0777);
 		}
 
-		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);




More information about the asterisk-commits mailing list