[Asterisk-code-review] res corosync: Add check for config file before calling coros... (asterisk[master])

George Joseph asteriskteam at digium.com
Wed Apr 22 16:27:07 CDT 2015


George Joseph has uploaded a new change for review.

  https://gerrit.asterisk.org/224

Change subject: res_corosync: Add check for config file before calling corosync apis
......................................................................

res_corosync: Add check for config file before calling corosync apis

res_corosync isn't compatible with some distributions and exits with
LOAD_FAILURE causing Asterisk to terminate, even if there was no
res_corosync.conf file.

This patch adds a check for the config file before calling any
corosync apis and returns a DECLINE if not found.  Asterisk
loading continues.

Change-Id: Iaf94a9431a4922ec4ec994003f02135acfdd3889
---
M res/res_corosync.c
1 file changed, 12 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/24/224/1

diff --git a/res/res_corosync.c b/res/res_corosync.c
index 6e73727..1502b5d 100644
--- a/res/res_corosync.c
+++ b/res/res_corosync.c
@@ -770,19 +770,10 @@
 	return res;
 }
 
-static int load_config(unsigned int reload)
+static int load_config(struct ast_config *cfg, unsigned int reload)
 {
-	static const char filename[] = "res_corosync.conf";
-	struct ast_config *cfg;
 	const char *cat = NULL;
-	struct ast_flags config_flags = { 0 };
 	int res = 0;
-
-	cfg = ast_config_load(filename, config_flags);
-
-	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
-		return -1;
-	}
 
 	while ((cat = ast_category_browse(cfg, cat))) {
 		if (!strcasecmp(cat, "general")) {
@@ -865,6 +856,15 @@
 	cs_error_t cs_err;
 	enum ast_module_load_result res = AST_MODULE_LOAD_FAILURE;
 	struct cpg_name name;
+	static const char filename[] = "res_corosync.conf";
+	struct ast_config *cfg;
+	struct ast_flags config_flags = { 0 };
+
+	cfg = ast_config_load(filename, config_flags);
+
+	if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEINVALID) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
 
 	corosync_aggregate_topic = stasis_topic_create("corosync_aggregate_topic");
 	if (!corosync_aggregate_topic) {
@@ -913,7 +913,7 @@
 		goto failed;
 	}
 
-	if (load_config(0)) {
+	if (load_config(cfg, 0)) {
 		/* simply not configured is not a fatal error */
 		res = AST_MODULE_LOAD_DECLINE;
 		goto failed;
@@ -924,6 +924,7 @@
 	return AST_MODULE_LOAD_SUCCESS;
 
 failed:
+	ast_config_destroy(cfg);
 	cleanup_module();
 
 	return res;

-- 
To view, visit https://gerrit.asterisk.org/224
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf94a9431a4922ec4ec994003f02135acfdd3889
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <george.joseph at fairview5.com>



More information about the asterisk-code-review mailing list