diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-12-02 09:34:23 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-12-02 09:34:23 +0000 |
commit | 6b4f71fc4c88aa11eb8ab8da76c98172ae10da68 (patch) | |
tree | 77248effaf87935a16449dea2b1d4fa5e6bf609f /main/autoservice.c | |
parent | 213a686818ae3b52921ac398852d0ffdff4f5f73 (diff) |
Clarify the return value on autoservice. Specifically, if you started
autoservice and autoservice was already on, it would erroneously return an
error.
Reported by: adiemus
Patch by: dimas
(Closes issue #11433)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@90432 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/autoservice.c')
-rw-r--r-- | main/autoservice.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/main/autoservice.c b/main/autoservice.c index 61c37088a..dc5ad81bf 100644 --- a/main/autoservice.c +++ b/main/autoservice.c @@ -137,7 +137,7 @@ static void *autoservice_run(void *ign) int ast_autoservice_start(struct ast_channel *chan) { - int res = -1; + int res = 0; struct asent *as; AST_LIST_LOCK(&aslist); @@ -151,11 +151,16 @@ int ast_autoservice_start(struct ast_channel *chan) } /* If not, start autoservice on channel */ - if (!as && (as = ast_calloc(1, sizeof(*as)))) { + if (as) { + /* Entry extist, autoservice is already handling this channel */ + } else if ((as = ast_calloc(1, sizeof(*as))) == NULL) { + /* Memory allocation failed */ + res = -1; + } else { + /* New entry created */ as->chan = chan; as->use_count = 1; AST_LIST_INSERT_HEAD(&aslist, as, list); - res = 0; if (asthread == AST_PTHREADT_NULL) { /* need start the thread */ if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) { ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n"); @@ -180,7 +185,7 @@ int ast_autoservice_stop(struct ast_channel *chan) struct asent *as; AST_LIST_HEAD_NOLOCK(, ast_frame) dtmf_frames; struct ast_frame *f; - int removed = 1; + int removed = 0; AST_LIST_HEAD_INIT_NOLOCK(&dtmf_frames); @@ -188,13 +193,12 @@ int ast_autoservice_stop(struct ast_channel *chan) AST_LIST_TRAVERSE_SAFE_BEGIN(&aslist, as, list) { if (as->chan == chan) { as->use_count--; - if (as->use_count) { - removed = 0; + if (as->use_count) break; - } AST_LIST_REMOVE_CURRENT(&aslist, list); AST_LIST_APPEND_LIST(&dtmf_frames, &as->dtmf_frames, frame_list); free(as); + removed = 1; if (!chan->_softhangup) res = 0; break; |