Blame SOURCES/bz1181107-global-data-after-parse.patch

a91f95
From 87088c1751b5788a30062f55a1b585c4eb5db5bf Mon Sep 17 00:00:00 2001
a91f95
From: Ryan O'Hara <rohara@redhat.com>
a91f95
Date: Thu, 14 May 2015 12:03:33 -0500
a91f95
Subject: [PATCH] Set global data default values after parsing config file
a91f95
a91f95
This patch will defer setting the global data default values until
a91f95
after the config file has been parsed. This will potentially avoid two
a91f95
calls to getaddrinfo. For example, if the router_id and/or email_from
a91f95
parameters are set in the config file, there is no need to call
a91f95
getaddrinfo twice in order to set a default value. Instead, this patch
a91f95
will check to see if they values are unset after parsing the config
a91f95
file. Note that email_from and smtp_connection_to are only set to a
a91f95
default value if they are unitialized and smtp_server is specified.
a91f95
---
a91f95
 keepalived/check/check_daemon.c  |  1 +
a91f95
 keepalived/core/global_data.c    | 32 +++++++++++++++++++-------------
a91f95
 keepalived/include/global_data.h |  1 +
a91f95
 keepalived/vrrp/vrrp_daemon.c    |  1 +
a91f95
 4 files changed, 22 insertions(+), 13 deletions(-)
a91f95
a91f95
diff --git a/keepalived/check/check_daemon.c b/keepalived/check/check_daemon.c
a91f95
index 240ad00..3ea199e 100644
a91f95
--- a/keepalived/check/check_daemon.c
a91f95
+++ b/keepalived/check/check_daemon.c
a91f95
@@ -112,6 +112,7 @@ start_check(void)
a91f95
 		stop_check();
a91f95
 		return;
a91f95
 	}
a91f95
+	init_global_data(global_data);
a91f95
 
a91f95
 	/* Post initializations */
a91f95
 	log_message(LOG_INFO, "Configuration is using : %lu Bytes", mem_allocated);
a91f95
diff --git a/keepalived/core/global_data.c b/keepalived/core/global_data.c
a91f95
index 2ef93ac..52bbee1 100644
a91f95
--- a/keepalived/core/global_data.c
a91f95
+++ b/keepalived/core/global_data.c
a91f95
@@ -88,18 +88,6 @@ set_default_mcast_group(data_t * data)
a91f95
 	inet_stosockaddr("ff02::12", 0, &data->vrrp_mcast_group6);
a91f95
 }
a91f95
 
a91f95
-static void
a91f95
-set_default_values(data_t * data)
a91f95
-{
a91f95
-	/* No global data so don't default */
a91f95
-	if (!data)
a91f95
-		return;
a91f95
-	set_default_router_id(data);
a91f95
-	set_default_smtp_connection_timeout(data);
a91f95
-	set_default_email_from(data);
a91f95
-	set_default_mcast_group(data);
a91f95
-}
a91f95
-
a91f95
 /* email facility functions */
a91f95
 static void
a91f95
 free_email(void *data)
a91f95
@@ -134,11 +122,29 @@ alloc_global_data(void)
a91f95
 	new = (data_t *) MALLOC(sizeof(data_t));
a91f95
 	new->email = alloc_list(free_email, dump_email);
a91f95
 
a91f95
-	set_default_values(new);
a91f95
+	set_default_mcast_group(new);
a91f95
+
a91f95
 	return new;
a91f95
 }
a91f95
 
a91f95
 void
a91f95
+init_global_data(data_t * data)
a91f95
+{
a91f95
+	if (!data->router_id) {
a91f95
+		set_default_router_id(data);
a91f95
+	}
a91f95
+
a91f95
+	if (data->smtp_server.ss_family) {
a91f95
+		if (!data->smtp_connection_to) {
a91f95
+			set_default_smtp_connection_timeout(data);
a91f95
+		}
a91f95
+		if (!data->email_from) {
a91f95
+			set_default_email_from(data);
a91f95
+		}
a91f95
+	}
a91f95
+}
a91f95
+
a91f95
+void
a91f95
 free_global_data(data_t * data)
a91f95
 {
a91f95
 	free_list(data->email);
a91f95
diff --git a/keepalived/include/global_data.h b/keepalived/include/global_data.h
a91f95
index 896480c..3e429da 100644
a91f95
--- a/keepalived/include/global_data.h
a91f95
+++ b/keepalived/include/global_data.h
a91f95
@@ -64,6 +64,7 @@ extern data_t *global_data; /* Global configuration data */
a91f95
 /* Prototypes */
a91f95
 extern void alloc_email(char *);
a91f95
 extern data_t *alloc_global_data(void);
a91f95
+extern void init_global_data(data_t *);
a91f95
 extern void free_global_data(data_t *);
a91f95
 extern void dump_global_data(data_t *);
a91f95
 
a91f95
diff --git a/keepalived/vrrp/vrrp_daemon.c b/keepalived/vrrp/vrrp_daemon.c
a91f95
index 755741b..b6369de 100644
a91f95
--- a/keepalived/vrrp/vrrp_daemon.c
a91f95
+++ b/keepalived/vrrp/vrrp_daemon.c
a91f95
@@ -123,6 +123,7 @@ start_vrrp(void)
a91f95
 		stop_vrrp();
a91f95
 		return;
a91f95
 	}
a91f95
+	init_global_data(global_data);
a91f95
 
a91f95
 #ifdef _WITH_LVS_
a91f95
 	if (vrrp_ipvs_needed()) {
a91f95
-- 
a91f95
1.9.3
a91f95