[asterisk-commits] wdoekes: trunk r350181 - in /trunk: ./ main/db.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 9 13:37:29 CST 2012


Author: wdoekes
Date: Mon Jan  9 13:37:23 2012
New Revision: 350181

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=350181
Log:
Fix shutdown handling of sqlite3 astdb.

If a db_sync was scheduled just before shutdown, the atexit code calling
db_sync would have no effect, causing the astdb commit thread to stay
alive. This caused the SIP/realtime_sipregs test to fail. (The fallback
kill would run the atexit code again and that would wreak havoc.) This
fixes that the atexit kill condition is picked up properly.

(closes issue ASTERISK-18883)
Reviewed by: Terry Wilson

Review: https://reviewboard.asterisk.org/r/1659
........

Merged revisions 350180 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    trunk/   (props changed)
    trunk/main/db.c

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

Modified: trunk/main/db.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/db.c?view=diff&rev=350181&r1=350180&r2=350181
==============================================================================
--- trunk/main/db.c (original)
+++ trunk/main/db.c Mon Jan  9 13:37:23 2012
@@ -891,6 +891,15 @@
 		ast_mutex_unlock(&dblock);
 		sleep(1);
 		ast_mutex_lock(&dblock);
+		/* Unfortunately, it is possible for signaling to happen
+		 * when we're not waiting: in the bit when we're unlocked
+		 * above. Do the do-exit check here again. (We could do
+		 * it once, but that would impose a forced delay of 1
+		 * second always.) */
+		if (doexit) {
+			ast_mutex_unlock(&dblock);
+			break;
+		}
 	}
 
 	return NULL;
@@ -898,8 +907,13 @@
 
 static void astdb_atexit(void)
 {
+	/* Set doexit to 1 to kill thread. db_sync must be called with
+	 * mutex held. */
 	doexit = 1;
+	ast_mutex_lock(&dblock);
 	db_sync();
+	ast_mutex_unlock(&dblock);
+
 	pthread_join(syncthread, NULL);
 	ast_mutex_lock(&dblock);
 	sqlite3_close(astdb);




More information about the asterisk-commits mailing list