[asterisk-commits] jpeeler: branch 1.6.2 r227947 - in /branches/1.6.2: ./ res/res_monitor.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 4 17:53:48 CST 2009


Author: jpeeler
Date: Wed Nov  4 17:53:43 2009
New Revision: 227947

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=227947
Log:
Merged revisions 227945 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r227945 | jpeeler | 2009-11-04 17:50:59 -0600 (Wed, 04 Nov 2009) | 21 lines
  
  Merged revisions 227944 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r227944 | jpeeler | 2009-11-04 17:47:08 -0600 (Wed, 04 Nov 2009) | 14 lines
    
    Fix incorrect filename comparsion after monitor file change
    
    The logic to detect if a requested file is indeed a different file from the
    current file was incorrect. The main issue being confusion of the use of
    filename_base which was previously set without pathing information and then
    compared to another full path. Robust file comparison logic has been added
    to properly check if two files are the same even if symlinks are used.
    
    (closes issue #15313)
    Reported by: caspy
    Patches: 
          20091103__issue15313__1.4.diff.txt uploaded by jpeeler (license 325)
          but mostly tilghman's work
  ........
................

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/res/res_monitor.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/res/res_monitor.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/res/res_monitor.c?view=diff&rev=227947&r1=227946&r2=227947
==============================================================================
--- branches/1.6.2/res/res_monitor.c (original)
+++ branches/1.6.2/res/res_monitor.c Wed Nov  4 17:53:43 2009
@@ -177,7 +177,8 @@
 						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));
+			snprintf(monitor->filename_base, FILENAME_MAX, "%s/%s",
+					 ast_config_AST_MONITOR_DIR, fname_base);
 		} else {
 			ast_mutex_lock(&monitorlock);
 			snprintf(monitor->read_filename, FILENAME_MAX, "%s/audio-in-%ld",
@@ -422,12 +423,44 @@
 		int directory = strchr(fname_base, '/') ? 1 : 0;
 		const char *absolute = *fname_base == '/' ? "" : "/";
 		char tmpstring[sizeof(chan->monitor->filename_base)] = "";
+		int i, fd[2] = { -1, -1 }, doexit = 0;
 
 		/* 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");
+
+		/*!\note We cannot just compare filenames, due to symlinks, relative
+		 * paths, and other possible filesystem issues.  We could use
+		 * realpath(3), but its use is discouraged.  However, if we try to
+		 * create the same file from two different paths, the second will
+		 * fail, and so we have our notification that the filenames point to
+		 * the same path.
+		 *
+		 * Remember, also, that we're using the basename of the file (i.e.
+		 * the file without the format suffix), so it does not already exist
+		 * and we aren't interfering with the recording itself.
+		 */
+		ast_debug(2, "comparing tmpstring %s to filename_base %s\n", tmpstring, chan->monitor->filename_base);
+		
+		if ((fd[0] = open(tmpstring, O_CREAT | O_WRONLY, 0644)) < 0 ||
+			(fd[1] = open(chan->monitor->filename_base, O_CREAT | O_EXCL | O_WRONLY, 0644)) < 0) {
+			if (fd[0] < 0) {
+				ast_log(LOG_ERROR, "Unable to compare filenames: %s\n", strerror(errno));
+			} else {
+				ast_debug(2, "No need to rename monitor filename to itself\n");
+			}
+			doexit = 1;
+		}
+
+		/* Cleanup temporary files */
+		for (i = 0; i < 2; i++) {
+			if (fd[i] >= 0) {
+				while (close(fd[i]) < 0 && errno == EINTR);
+			}
+		}
+		unlink(tmpstring);
+		unlink(chan->monitor->filename_base);
+
+		if (doexit) {
 			UNLOCK_IF_NEEDED(chan, need_lock);
 			return 0;
 		}




More information about the asterisk-commits mailing list