[asterisk-commits] mmichelson: trunk r118514 - in /trunk: ./ apps/app_chanspy.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 27 14:08:25 CDT 2008


Author: mmichelson
Date: Tue May 27 14:08:24 2008
New Revision: 118514

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

........
r118509 | mmichelson | 2008-05-27 14:07:26 -0500 (Tue, 27 May 2008) | 11 lines

Russell noted to me that in the case that separate threads use their
own addressing system, the fix I made for issue 12376 does not guarantee
uniqueness to the datastores' uids. Though I know of no system that works
this way, I am going to change this right now to prevent trying to track
down some future bug that may occur and cause untold hours of debugging
time to track down.

The change involves using a global counter which increases with each new
chanspy_ds which is created. This guarantees uniqueness.


........

Modified:
    trunk/   (props changed)
    trunk/apps/app_chanspy.c

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

Modified: trunk/apps/app_chanspy.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_chanspy.c?view=diff&rev=118514&r1=118513&r2=118514
==============================================================================
--- trunk/apps/app_chanspy.c (original)
+++ trunk/apps/app_chanspy.c Tue May 27 14:08:24 2008
@@ -217,6 +217,7 @@
 	AST_APP_OPTION('d', OPTION_DTMF_SWITCH_MODES),
 });
 
+int next_unique_id_to_use = 0;
 
 struct chanspy_translation_helper {
 	/* spy data */
@@ -293,6 +294,7 @@
 
 struct chanspy_ds {
 	struct ast_channel *chan;
+	char unique_id[20];
 	ast_mutex_t lock;
 };
 
@@ -541,13 +543,11 @@
 	if (chanspy_ds->chan) {
 		struct ast_datastore *datastore;
 		struct ast_channel *chan;
-		char uid[20];
 
 		chan = chanspy_ds->chan;
 
 		ast_channel_lock(chan);
-		snprintf(uid, sizeof(uid), "%p", chanspy_ds);
-		if ((datastore = ast_channel_datastore_find(chan, &chanspy_ds_info, uid))) {
+		if ((datastore = ast_channel_datastore_find(chan, &chanspy_ds_info, chanspy_ds->unique_id))) {
 			ast_channel_datastore_remove(chan, datastore);
 			/* chanspy_ds->chan is NULL after this call */
 			chanspy_ds_destroy(datastore->data);
@@ -565,13 +565,10 @@
 static struct chanspy_ds *setup_chanspy_ds(struct ast_channel *chan, struct chanspy_ds *chanspy_ds)
 {
 	struct ast_datastore *datastore = NULL;
-	char uid[20];
 
 	ast_mutex_lock(&chanspy_ds->lock);
 
-	snprintf(uid, sizeof(uid), "%p", chanspy_ds);
-
-	if (!(datastore = ast_channel_datastore_alloc(&chanspy_ds_info, uid))) {
+	if (!(datastore = ast_channel_datastore_alloc(&chanspy_ds_info, chanspy_ds->unique_id))) {
 		ast_mutex_unlock(&chanspy_ds->lock);
 		chanspy_ds = chanspy_ds_free(chanspy_ds);
 		ast_channel_unlock(chan);
@@ -644,6 +641,8 @@
 	}
 
 	ast_mutex_init(&chanspy_ds.lock);
+
+	snprintf(chanspy_ds.unique_id, sizeof(chanspy_ds.unique_id), "%d", ast_atomic_fetchadd_int(&next_unique_id_to_use, +1));
 
 	if (chan->_state != AST_STATE_UP)
 		ast_answer(chan);




More information about the asterisk-commits mailing list