[svn-commits] russell: trunk r363046 - /trunk/res/res_corosync.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Apr 21 06:46:11 CDT 2012


Author: russell
Date: Sat Apr 21 06:45:28 2012
New Revision: 363046

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=363046
Log:
res_corosync: Recover if corosync gets restarted.

If corosync gets restarted while Asterisk is running, automatically recover.

Modified:
    trunk/res/res_corosync.c

Modified: trunk/res/res_corosync.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_corosync.c?view=diff&rev=363046&r1=363045&r2=363046
==============================================================================
--- trunk/res/res_corosync.c (original)
+++ trunk/res/res_corosync.c Sat Apr 21 06:45:28 2012
@@ -196,6 +196,8 @@
 	while (!dispatch_thread.stop) {
 		int res;
 
+		cs_err = CS_OK;
+
 		pfd[0].revents = 0;
 		pfd[1].revents = 0;
 		pfd[2].revents = 0;
@@ -216,6 +218,48 @@
 			if ((cs_err = corosync_cfg_dispatch(cfg_handle, CS_DISPATCH_ALL)) != CS_OK) {
 				ast_log(LOG_WARNING, "Failed CFG dispatch: %d\n", cs_err);
 			}
+		}
+
+		if (cs_err == CS_ERR_LIBRARY || cs_err == CS_ERR_BAD_HANDLE) {
+			struct cpg_name name;
+
+			/* If corosync gets restarted out from under Asterisk, try to recover. */
+
+			ast_log(LOG_NOTICE, "Attempting to recover from corosync failure.\n");
+
+			if ((cs_err = corosync_cfg_initialize(&cfg_handle, &cfg_callbacks)) != CS_OK) {
+				ast_log(LOG_ERROR, "Failed to initialize cfg (%d)\n", (int) cs_err);
+				sleep(5);
+				continue;
+			}
+
+			if ((cs_err = cpg_initialize(&cpg_handle, &cpg_callbacks) != CS_OK)) {
+				ast_log(LOG_ERROR, "Failed to initialize cpg (%d)\n", (int) cs_err);
+				sleep(5);
+				continue;
+			}
+
+			if ((cs_err = cpg_fd_get(cpg_handle, &pfd[0].fd)) != CS_OK) {
+				ast_log(LOG_ERROR, "Failed to get CPG fd.\n");
+				sleep(5);
+				continue;
+			}
+
+			if ((cs_err = corosync_cfg_fd_get(cfg_handle, &pfd[1].fd)) != CS_OK) {
+				ast_log(LOG_ERROR, "Failed to get CFG fd.\n");
+				sleep(5);
+				continue;
+			}
+
+			ast_copy_string(name.value, "asterisk", sizeof(name.value));
+			name.length = strlen(name.value);
+			if ((cs_err = cpg_join(cpg_handle, &name)) != CS_OK) {
+				ast_log(LOG_ERROR, "Failed to join cpg (%d)\n", (int) cs_err);
+				sleep(5);
+				continue;
+			}
+
+			ast_log(LOG_NOTICE, "Corosync recovery complete.\n");
 		}
 	}
 




More information about the svn-commits mailing list