[Asterisk-code-review] res statsd.c: Made use defaults if the statsd.conf file does... (asterisk[16])

Richard Mudgett asteriskteam at digium.com
Tue Oct 2 17:12:21 CDT 2018


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/10385


Change subject: res_statsd.c: Made use defaults if the statsd.conf file does not exist.
......................................................................

res_statsd.c: Made use defaults if the statsd.conf file does not exist.

This module is an optional dependency of many modules.  If it declines to
load it then forces other modules that can optionally use this module to
also decline.

* Made use default configuration if there is a config error or the config
file does not exist.

Change-Id: If1068a582ec54ab7fb437265cb5370a97a825737
---
M res/res_statsd.c
1 file changed, 19 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/85/10385/1

diff --git a/res/res_statsd.c b/res/res_statsd.c
index 3e08152..3e52c21 100644
--- a/res/res_statsd.c
+++ b/res/res_statsd.c
@@ -339,9 +339,25 @@
 		"", OPT_CHAR_ARRAY_T, 0,
 		CHARFLDSET(struct conf_global_options, prefix));
 
-	if (aco_process_config(&cfg_info, 0)) {
-		aco_info_destroy(&cfg_info);
-		return AST_MODULE_LOAD_DECLINE;
+	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
+		struct conf *cfg;
+
+		ast_log(LOG_NOTICE, "Could not load statsd config; using defaults\n");
+		cfg = conf_alloc();
+		if (!cfg) {
+			aco_info_destroy(&cfg_info);
+			return AST_MODULE_LOAD_DECLINE;
+		}
+
+		if (aco_set_defaults(&global_option, "general", cfg->global)) {
+			ast_log(LOG_ERROR, "Failed to initialize statsd defaults.\n");
+			ao2_ref(cfg, -1);
+			aco_info_destroy(&cfg_info);
+			return AST_MODULE_LOAD_DECLINE;
+		}
+
+		ao2_global_obj_replace_unref(confs, cfg);
+		ao2_ref(cfg, -1);
 	}
 
 	if (!is_enabled()) {

-- 
To view, visit https://gerrit.asterisk.org/10385
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: newchange
Gerrit-Change-Id: If1068a582ec54ab7fb437265cb5370a97a825737
Gerrit-Change-Number: 10385
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181002/489ef27a/attachment.html>


More information about the asterisk-code-review mailing list