[asterisk-commits] tzafrir: branch group/zapata_conf r84889 - /team/group/zapata_conf/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Oct 6 21:59:45 CDT 2007


Author: tzafrir
Date: Sat Oct  6 21:59:44 2007
New Revision: 84889

URL: http://svn.digium.com/view/asterisk?view=rev&rev=84889
Log:
* Re-enable 'zap restart': it should call zap_setup(0). Otherwise it's a
  reload.
* Use the same code as __unload_module to destroy all channels.
* Add a seond of delay, to give zaptel channels time to get freed (why?)
* Fix a double release in do_monitor.

Modified:
    team/group/zapata_conf/channels/chan_zap.c

Modified: team/group/zapata_conf/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/group/zapata_conf/channels/chan_zap.c?view=diff&rev=84889&r1=84888&r2=84889
==============================================================================
--- team/group/zapata_conf/channels/chan_zap.c (original)
+++ team/group/zapata_conf/channels/chan_zap.c Sat Oct  6 21:59:44 2007
@@ -7143,14 +7143,17 @@
 		/* Lock the interface list */
 		ast_mutex_lock(&iflock);
 		if (!pfds || (lastalloc != ifcount)) {
-			if (pfds)
+			if (pfds) {
 				ast_free(pfds);
+				pfds = NULL;
+			}
 			if (ifcount) {
 				if (!(pfds = ast_calloc(1, ifcount * sizeof(*pfds)))) {
 					ast_mutex_unlock(&iflock);
 					return NULL;
 				}
 			}
+
 			lastalloc = ifcount;
 		}
 		/* Build the stuff we're going to poll on, that is the socket of every
@@ -10821,16 +10824,17 @@
 }
 
 static int setup_zap(int reload);
+static void destroy_all_channels(void);
+
 static int zap_restart(void)
 {
 	ast_verb(1, "Destroying channels and reloading zaptel configuration.\n");
-	while (iflist) {
-		ast_debug(1, "Destroying zaptel channel no. %d\n", iflist->channel);
-		/* Also updates iflist: */
-		destroy_channel(NULL, iflist, 1);
-	}
+	destroy_all_channels();
+
+	/* FIXME: We need to wait "for a while" after destroying channels. */
+	sleep(1);
 	ast_debug(1, "Channels destroyed. Now re-reading config.\n");
-	if (setup_zap(2) != 0) {
+	if (setup_zap(0) != 0) {
 		ast_log(LOG_WARNING, "Reload channels from zap config failed!\n");
 		return 1;
 	}
@@ -11499,46 +11503,10 @@
 	return 0;
 }
 
-static int __unload_module(void)
+static void destroy_all_channels(void)
 {
 	int x;
 	struct zt_pvt *p, *pl;
-
-#ifdef HAVE_PRI
-	int i;
-	for (i = 0; i < NUM_SPANS; i++) {
-		if (pris[i].master != AST_PTHREADT_NULL) 
-			pthread_cancel(pris[i].master);
-	}
-	ast_cli_unregister_multiple(zap_pri_cli, sizeof(zap_pri_cli) / sizeof(struct ast_cli_entry));
-	ast_unregister_application(zap_send_keypad_facility_app);
-#endif
-	ast_cli_unregister_multiple(zap_cli, sizeof(zap_cli) / sizeof(struct ast_cli_entry));
-	ast_manager_unregister( "ZapDialOffhook" );
-	ast_manager_unregister( "ZapHangup" );
-	ast_manager_unregister( "ZapTransfer" );
-	ast_manager_unregister( "ZapDNDoff" );
-	ast_manager_unregister( "ZapDNDon" );
-	ast_manager_unregister("ZapShowChannels");
-	ast_manager_unregister("ZapRestart");
-	ast_channel_unregister(&zap_tech);
-	ast_mutex_lock(&iflock);
-	/* Hangup all interfaces if they have an owner */
-	p = iflist;
-	while (p) {
-		if (p->owner)
-			ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
-		p = p->next;
-	}
-	ast_mutex_unlock(&iflock);
-	ast_mutex_lock(&monlock);
-	if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
-		pthread_cancel(monitor_thread);
-		pthread_kill(monitor_thread, SIGURG);
-		pthread_join(monitor_thread, NULL);
-	}
-	monitor_thread = AST_PTHREADT_STOP;
-	ast_mutex_unlock(&monlock);
 
 	ast_mutex_lock(&iflock);
 	/* Destroy all the interfaces and free their memory */
@@ -11561,6 +11529,49 @@
 	iflist = NULL;
 	ifcount = 0;
 	ast_mutex_unlock(&iflock);
+}
+
+static int __unload_module(void)
+{
+	struct zt_pvt *p;
+
+#ifdef HAVE_PRI
+	int i;
+	for (i = 0; i < NUM_SPANS; i++) {
+		if (pris[i].master != AST_PTHREADT_NULL) 
+			pthread_cancel(pris[i].master);
+	}
+	ast_cli_unregister_multiple(zap_pri_cli, sizeof(zap_pri_cli) / sizeof(struct ast_cli_entry));
+	ast_unregister_application(zap_send_keypad_facility_app);
+#endif
+	ast_cli_unregister_multiple(zap_cli, sizeof(zap_cli) / sizeof(struct ast_cli_entry));
+	ast_manager_unregister( "ZapDialOffhook" );
+	ast_manager_unregister( "ZapHangup" );
+	ast_manager_unregister( "ZapTransfer" );
+	ast_manager_unregister( "ZapDNDoff" );
+	ast_manager_unregister( "ZapDNDon" );
+	ast_manager_unregister("ZapShowChannels");
+	ast_manager_unregister("ZapRestart");
+	ast_channel_unregister(&zap_tech);
+	ast_mutex_lock(&iflock);
+	/* Hangup all interfaces if they have an owner */
+	p = iflist;
+	while (p) {
+		if (p->owner)
+			ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
+		p = p->next;
+	}
+	ast_mutex_unlock(&iflock);
+	ast_mutex_lock(&monlock);
+	if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
+		pthread_cancel(monitor_thread);
+		pthread_kill(monitor_thread, SIGURG);
+		pthread_join(monitor_thread, NULL);
+	}
+	monitor_thread = AST_PTHREADT_STOP;
+	ast_mutex_unlock(&monlock);
+
+	destroy_all_channels();
 #ifdef HAVE_PRI		
 	for (i = 0; i < NUM_SPANS; i++) {
 		if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL))




More information about the asterisk-commits mailing list