[asterisk-commits] file: branch 1.4 r89610 - /branches/1.4/main/dial.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 26 15:10:29 CST 2007


Author: file
Date: Mon Nov 26 15:10:29 2007
New Revision: 89610

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89610
Log:
Fix issues with async dialing with an application executing. The application has to be terminated and control returned to the thread before hanging things up. (issue #BE-252)

Modified:
    branches/1.4/main/dial.c

Modified: branches/1.4/main/dial.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/dial.c?view=diff&rev=89610&r1=89609&r2=89610
==============================================================================
--- branches/1.4/main/dial.c (original)
+++ branches/1.4/main/dial.c Mon Nov 26 15:10:29 2007
@@ -61,6 +61,7 @@
 	const char *device;                    /*! Device being dialed */
 	void *options[AST_DIAL_OPTION_MAX];    /*! Channel specific options */
 	int cause;                             /*! Cause code in case of failure */
+	int is_running_app:1;                  /*! Is this running an application? */
 	struct ast_channel *owner;             /*! Asterisk channel */
 	AST_LIST_ENTRY(ast_dial_channel) list; /*! Linked list information */
 };
@@ -123,8 +124,9 @@
 }
 
 /* Application execution function for 'ANSWER_EXEC' option */
-static void answer_exec_run(struct ast_channel *chan, char *app, char *args)
-{
+static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args)
+{
+	struct ast_channel *chan = dial_channel->owner;
 	struct ast_app *ast_app = pbx_findapp(app);
 
 	/* If the application was not found, return immediately */
@@ -133,6 +135,12 @@
 
 	/* All is well... execute the application */
 	pbx_exec(chan, ast_app, args);
+
+	/* If another thread is not taking over hang up the channel */
+	if (dial->thread != AST_PTHREADT_STOP) {
+		ast_hangup(chan);
+		dial_channel->owner = NULL;
+	}
 
 	return;
 }
@@ -510,8 +518,11 @@
 			channel->owner = NULL;
 		}
 		/* If ANSWER_EXEC is enabled as an option, execute application on answered channel */
-		if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC)))
-			answer_exec_run(who, answer_exec->app, answer_exec->args);
+		if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) {
+			channel->is_running_app = 1;
+			answer_exec_run(dial, channel, answer_exec->app, answer_exec->args);
+			channel->is_running_app = 0;
+		}
 	} else if (dial->state == AST_DIAL_RESULT_HANGUP) {
 		/* Hangup everything */
 		AST_LIST_TRAVERSE(&dial->channels, channel, list) {
@@ -615,8 +626,16 @@
 	/* Stop the thread */
 	dial->thread = AST_PTHREADT_STOP;
 
-	/* Now we signal it with SIGURG so it will break out of it's waitfor */
-	pthread_kill(thread, SIGURG);
+	/* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
+	if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
+		struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
+		ast_channel_lock(chan);
+		ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT);
+		ast_channel_unlock(chan);
+	} else {
+		/* Now we signal it with SIGURG so it will break out of it's waitfor */
+		pthread_kill(thread, SIGURG);
+	}
 
 	/* Finally wait for the thread to exit */
 	pthread_join(thread, NULL);




More information about the asterisk-commits mailing list