aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-27 19:07:26 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-05-27 19:07:26 +0000
commitbbb5aaa62f60629c105f2d79e68221476046f06a (patch)
tree3699d169e06e24f37cdeb5f0a62bb05a1cb9035e /apps
parentfa784f040cfa4bde4495976b9760ea47278a13e1 (diff)
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. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@118509 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_chanspy.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/apps/app_chanspy.c b/apps/app_chanspy.c
index 295ba9a37..6432f1bbb 100644
--- a/apps/app_chanspy.c
+++ b/apps/app_chanspy.c
@@ -142,6 +142,7 @@ AST_APP_OPTIONS(spy_opts, {
AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD),
});
+int next_unique_id_to_use = 0;
struct chanspy_translation_helper {
/* spy data */
@@ -216,6 +217,7 @@ static int start_spying(struct ast_channel *chan, const char *spychan_name, stru
struct chanspy_ds {
struct ast_channel *chan;
+ char unique_id[20];
ast_mutex_t lock;
};
@@ -415,13 +417,11 @@ static struct chanspy_ds *chanspy_ds_free(struct chanspy_ds *chanspy_ds)
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);
@@ -439,13 +439,10 @@ static struct chanspy_ds *chanspy_ds_free(struct chanspy_ds *chanspy_ds)
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);
@@ -504,6 +501,8 @@ static int common_exec(struct ast_channel *chan, const struct ast_flags *flags,
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);