Blob Blame History Raw
From 99ad17d4906f478c51b58ab8f288edbca0bab906 Mon Sep 17 00:00:00 2001
From: YAMAMOTO Masaya <pandax381@gmail.com>
Date: Fri, 14 Jul 2017 14:34:28 +0900
Subject: [PATCH 6/8] Fix to match coding style

---
 keepalived/check/check_api.c   | 22 ++++++++++------------
 keepalived/check/check_dns.c   | 20 +++++++++-----------
 keepalived/check/check_http.c  | 26 ++++++++++++--------------
 keepalived/check/check_misc.c  | 18 ++++++++----------
 keepalived/check/check_smtp.c  | 26 ++++++++++++--------------
 keepalived/check/check_tcp.c   | 18 ++++++++----------
 keepalived/include/check_api.h |  6 +++---
 7 files changed, 62 insertions(+), 74 deletions(-)

diff --git a/keepalived/check/check_api.c b/keepalived/check/check_api.c
index a722fc84..1d915414 100644
--- a/keepalived/check/check_api.c
+++ b/keepalived/check/check_api.c
@@ -81,7 +81,7 @@ dump_conn_opts(void *data)
 void
 queue_checker(void (*free_func) (void *), void (*dump_func) (void *)
 	      , int (*launch) (thread_t *)
-	      , int (*compare) (void *, void *)
+	      , bool (*compare) (void *, void *)
 	      , void *data
 	      , conn_opts_t *co)
 {
@@ -120,28 +120,26 @@ queue_checker(void (*free_func) (void *), void (*dump_func) (void *)
 	}
 }
 
-int
+bool
 compare_conn_opts(conn_opts_t *a, conn_opts_t *b)
 {
 	if (a == b)
-		return 0;
+		return true;
 
 	if (!a || !b)
-		goto err;
+		return false;
 	if (!sockstorage_equal(&a->dst, &b->dst))
-		goto err;
+		return false;
 	if (!sockstorage_equal(&a->bindto, &b->bindto))
-		goto err;
-	//if (a->connection_to != b->connection_to)
-	//	goto err;
+		return false;
+	if (a->connection_to != b->connection_to)
+		return false;
 #ifdef _WITH_SO_MARK_
 	if (a->fwmark != b->fwmark)
-		goto err;
+		return false;
 #endif
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 static void
diff --git a/keepalived/check/check_dns.c b/keepalived/check/check_dns.c
index 84a5f56d..603742a4 100644
--- a/keepalived/check/check_dns.c
+++ b/keepalived/check/check_dns.c
@@ -388,24 +388,22 @@ dns_dump(void *data)
 	log_message(LOG_INFO, "   Name = %s", dns_check->name);
 }
 
-static int
-dns_compare(void *a, void *b)
+static bool 
+dns_check_compare(void *a, void *b)
 {
 	dns_check_t *old = CHECKER_DATA(a);
 	dns_check_t *new = CHECKER_DATA(b);
 
-	if (compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)) != 0)
-		goto err;
+	if (!compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)))
+		return false;
 	if (old->retry != new->retry)
-		goto err;
+		return false;
 	if (strcmp(old->type, new->type) != 0)
-		goto err;
+		return false;
 	if (strcmp(old->name, new->name) != 0)
-		goto err;
+		return false;
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 static void
@@ -417,7 +415,7 @@ dns_check_handler(__attribute__((unused)) vector_t * strvec)
 	dns_check->type = DNS_DEFAULT_TYPE;
 	dns_check->name = DNS_DEFAULT_NAME;
 	queue_checker(dns_free, dns_dump, dns_connect_thread,
-		      dns_compare, dns_check, CHECKER_NEW_CO());
+		      dns_check_compare, dns_check, CHECKER_NEW_CO());
 }
 
 static void
diff --git a/keepalived/check/check_http.c b/keepalived/check/check_http.c
index c2089a3b..1ad395cf 100644
--- a/keepalived/check/check_http.c
+++ b/keepalived/check/check_http.c
@@ -123,36 +123,34 @@ alloc_http_get(char *proto)
 	return http_get_chk;
 }
 
-static int
-compare_http_get_check(void *a, void *b)
+static bool
+http_get_check_compare(void *a, void *b)
 {
 	http_checker_t *old = CHECKER_DATA(a);
 	http_checker_t *new = CHECKER_DATA(b);
 	size_t n;
 	url_t *u1, *u2;
 
-	if (compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)) != 0)
-		goto err;
+	if (!compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)))
+		return false;
 	if (old->nb_get_retry != new->nb_get_retry)
-		goto err;
+		return false;
 	if (old->delay_before_retry != new->delay_before_retry)
-		goto err;
+		return false;
 	if (LIST_SIZE(old->url) != LIST_SIZE(new->url))
-		goto err;
+		return false;
 	for (n = 0; n < LIST_SIZE(new->url); n++) {
 		u1 = (url_t *)list_element(old->url, n);
 		u2 = (url_t *)list_element(new->url, n);
 		if (strcmp(u1->path, u2->path) != 0)
-			goto err;
+			return false;
 		if (strcmp(u1->digest, u2->digest) != 0)
-			goto err;
+			return false;
 		if (u1->status_code != u2->status_code)
-			goto err;
+			return false;
 	}
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 static void
@@ -164,7 +162,7 @@ http_get_handler(vector_t *strvec)
 	/* queue new checker */
 	http_get_chk = alloc_http_get(str);
 	queue_checker(free_http_get_check, dump_http_get_check,
-		      http_connect_thread, compare_http_get_check,
+		      http_connect_thread, http_get_check_compare,
 		      http_get_chk, CHECKER_NEW_CO());
 }
 
diff --git a/keepalived/check/check_misc.c b/keepalived/check/check_misc.c
index 311a1127..f1f66955 100644
--- a/keepalived/check/check_misc.c
+++ b/keepalived/check/check_misc.c
@@ -72,24 +72,22 @@ dump_misc_check(void *data)
 	log_message(LOG_INFO, "   insecure = %s", misck_checker->insecure ? "Yes" : "No");
 }
 
-static int
-compare_misc_check(void *a, void *b)
+static bool
+misc_check_compare(void *a, void *b)
 {
 	misc_checker_t *old = CHECKER_DATA(a);
 	misc_checker_t *new = CHECKER_DATA(b);
 
 	if (strcmp(old->path, new->path) != 0)
-		goto err;
+		return false;
 	if (old->timeout != new->timeout)
-		goto err;
+		return false;
 	if (old->dynamic != new->dynamic)
-		goto err;
+		return false;
 	if (old->uid != new->uid || new->gid != new->gid)
-		goto err;
+		return false;
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 static void
@@ -169,7 +167,7 @@ log_message(LOG_INFO, "Setting uid.gid");
 	}
 
 	/* queue new checker */
-	queue_checker(free_misc_check, dump_misc_check, misc_check_thread, compare_misc_check, misck_checker, NULL);
+	queue_checker(free_misc_check, dump_misc_check, misc_check_thread, misc_check_compare, misck_checker, NULL);
 	misck_checker = NULL;
 log_message(LOG_INFO, "Leaving misc_end_handler");
 }
diff --git a/keepalived/check/check_smtp.c b/keepalived/check/check_smtp.c
index e19511cc..44d15e01 100644
--- a/keepalived/check/check_smtp.c
+++ b/keepalived/check/check_smtp.c
@@ -82,8 +82,8 @@ dump_smtp_check(void *data)
 	dump_list(smtp_checker->host);
 }
 
-static int
-compare_smtp_check(void *a, void *b)
+static bool
+smtp_check_compare(void *a, void *b)
 {
 	smtp_checker_t *old = CHECKER_DATA(a);
 	smtp_checker_t *new = CHECKER_DATA(b);
@@ -91,26 +91,24 @@ compare_smtp_check(void *a, void *b)
 	smtp_host_t *h1, *h2;
 
 	if (strcmp(old->helo_name, new->helo_name) != 0)
-		goto err;
+		return false;
 	if (old->retry != new->retry)
-		goto err;
+		return false;
 	if (old->db_retry != new->db_retry)
-		goto err;
-	if (compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)) != 0)
-		goto err;
+		return false;
+	if (!compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)))
+		return false;
 	if (LIST_SIZE(old->host) != LIST_SIZE(new->host))
-		goto err;
+		return false;
 	for (n = 0; n < LIST_SIZE(new->host); n++) {
 		h1 = (smtp_host_t *)list_element(old->host, n);
 		h2 = (smtp_host_t *)list_element(new->host, n);
-		if (compare_conn_opts(h1, h2) != 0) {
-			goto err;
+		if (!compare_conn_opts(h1, h2)) {
+			return false;
 		}
 	}
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 /* Allocates a default host structure */
@@ -167,7 +165,7 @@ smtp_check_handler(__attribute__((unused)) vector_t *strvec)
 	 *               void *data, conn_opts_t *)
 	 */
 	queue_checker(free_smtp_check, dump_smtp_check, smtp_connect_thread,
-		      compare_smtp_check, smtp_checker, smtp_checker->default_co);
+		      smtp_check_compare, smtp_checker, smtp_checker->default_co);
 
 	/*
 	 * Last, allocate the list that will hold all the per host
diff --git a/keepalived/check/check_tcp.c b/keepalived/check/check_tcp.c
index 026a0e3c..1858f5fc 100644
--- a/keepalived/check/check_tcp.c
+++ b/keepalived/check/check_tcp.c
@@ -62,22 +62,20 @@ dump_tcp_check(void *data)
 	}
 }
 
-static int
-compare_tcp_check(void *a, void *b)
+static bool
+tcp_check_compare(void *a, void *b)
 {
 	tcp_check_t *old = CHECKER_DATA(a);
 	tcp_check_t *new = CHECKER_DATA(b);
 
-	if (compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)) != 0)
-		goto err;
+	if (!compare_conn_opts(CHECKER_CO(a), CHECKER_CO(b)))
+		return false;
 	if (old->n_retry != new->n_retry)
-		goto err;
+		return false;
 	if (old->delay_before_retry != new->delay_before_retry)
-		goto err;
+		return false;
 
-	return  0;
-err:
-	return -1;
+	return true;
 }
 
 static void
@@ -91,7 +89,7 @@ tcp_check_handler(__attribute__((unused)) vector_t *strvec)
 
 	/* queue new checker */
 	queue_checker(free_tcp_check, dump_tcp_check, tcp_connect_thread,
-		      compare_tcp_check, tcp_check, CHECKER_NEW_CO());
+		      tcp_check_compare, tcp_check, CHECKER_NEW_CO());
 }
 
 static void
diff --git a/keepalived/include/check_api.h b/keepalived/include/check_api.h
index 4a10a36b..c7bc297d 100644
--- a/keepalived/include/check_api.h
+++ b/keepalived/include/check_api.h
@@ -36,7 +36,7 @@ typedef struct _checker {
 	void				(*free_func) (void *);
 	void				(*dump_func) (void *);
 	int				(*launch) (struct _thread *);
-	int				(*compare) (void *, void *);
+	bool				(*compare) (void *, void *);
 	virtual_server_t		*vs;	/* pointer to the checker thread virtualserver */
 	real_server_t			*rs;	/* pointer to the checker thread realserver */
 	void				*data;
@@ -71,10 +71,10 @@ extern void init_checkers_queue(void);
 extern void dump_conn_opts(void *);
 extern void queue_checker(void (*free_func) (void *), void (*dump_func) (void *)
 			  , int (*launch) (thread_t *)
-			  , int (*compare) (void *, void *)
+			  , bool (*compare) (void *, void *)
 			  , void *
 			  , conn_opts_t *);
-extern int  compare_conn_opts(conn_opts_t *, conn_opts_t *);
+extern bool compare_conn_opts(conn_opts_t *, conn_opts_t *);
 extern void dump_checkers_queue(void);
 extern void free_checkers_queue(void);
 extern void register_checkers_thread(void);
-- 
2.20.1