[PATCH 5/8 v3] cld: modify cld-dns to use logging macros

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Colin McCabe <cmccabe@xxxxxxxxxxxxxx>
---
 include/cldc.h |    7 ++---
 lib/cldc-dns.c |   80 +++++++++++++++++++++-----------------------------------
 tools/cldcli.c |   12 +++++---
 3 files changed, 41 insertions(+), 58 deletions(-)

diff --git a/include/cldc.h b/include/cldc.h
index 1382a23..5419cc8 100644
--- a/include/cldc.h
+++ b/include/cldc.h
@@ -201,14 +201,13 @@ extern int cldc_udp_pkt_send(void *private,
 			  const void *buf, size_t buflen);
 
 /* cldc-dns */
-extern int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
-		 void (*act_log)(int prio, const char *fmt, ...));
+extern int cldc_getaddr(GList **host_list, const char *thishost,
+			struct hail_log *log);
 extern int cldc_saveaddr(struct cldc_host *hp,
 			 unsigned int priority,
 			 unsigned int weight, unsigned int port,
 			 unsigned int nlen, const char *name,
-			 bool verbose,
-			 void (*act_log)(int prio, const char *fmt, ...));
+			 struct hail_log *log);
 
 static inline bool seqid_after_eq(uint64_t a_, uint64_t b_)
 {
diff --git a/lib/cldc-dns.c b/lib/cldc-dns.c
index 89800ba..d58a8ba 100644
--- a/lib/cldc-dns.c
+++ b/lib/cldc-dns.c
@@ -21,8 +21,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 			 unsigned int priority,
 			 unsigned int weight, unsigned int port,
 			 unsigned int nlen, const char *name,
-			 bool verbose,
-			 void (*act_log)(int prio, const char *fmt, ...))
+			 struct hail_log *log)
 {
 	char portstr[11];
 	char *hostname;
@@ -47,7 +46,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 
 	rc = getaddrinfo(hostname, portstr, &hints, &res0);
 	if (rc) {
-		act_log(LOG_INFO, "getaddrinfo(%s,%s) failed: %s",
+		HAIL_INFO(log, "getaddrinfo(%s,%s) failed: %s",
 		       hostname, portstr, gai_strerror(rc));
 		rc = -EINVAL;
 		goto err_addr;
@@ -66,7 +65,7 @@ int cldc_saveaddr(struct cldc_host *hp,
 	}
 
 	if (!something_suitable) {
-		act_log(LOG_INFO, "Host %s port %u has no addresses",
+		HAIL_INFO(log, "Host %s port %u has no addresses",
 		       hostname, port);
 		rc = -EINVAL;
 		goto err_suitable;
@@ -77,11 +76,8 @@ int cldc_saveaddr(struct cldc_host *hp,
 	hp->prio = priority;
 	hp->weight = weight;
 
-	if (verbose) {
-		act_log(LOG_DEBUG,
-		       "Found CLD host %s prio %d weight %d",
-		       hostname, priority, weight);
-	}
+	HAIL_DEBUG(log, "Found CLD host %s prio %d weight %d",
+			hostname, priority, weight);
 
 	freeaddrinfo(res0);
 	return 0;
@@ -100,8 +96,7 @@ err_name:
  * on YP-driven networks with nonqualified hostnames (at least for now).
  */
 static int cldc_make_fqdn(char *buf, int size, const char *srvname,
-			  const char *thishost,
-		 	  void (*act_log)(int prio, const char *fmt, ...))
+			  const char *thishost, struct hail_log *log)
 {
 	char *s;
 	int nlen;
@@ -109,29 +104,26 @@ static int cldc_make_fqdn(char *buf, int size, const char *srvname,
 
 	nlen = strlen(srvname);
 	if (nlen >= size-20) {
-		act_log(LOG_INFO,
-		       "cldc_getaddr: internal error (nlen %d size %d)",
+		HAIL_INFO(log, "cldc_getaddr: internal error "
+			"(nlen %d size %d)",
 		       nlen, size);
 		return -1;
 	}
 
 	if (thishost == NULL) {
-		act_log(LOG_INFO,
-			"cldc_getaddr: internal error (null hostname)");
+		HAIL_INFO(log, "cldc_getaddr: internal error (null hostname)");
 		return -1;
 	}
 	if ((s = strchr(thishost, '.')) == NULL) {
-		act_log(LOG_INFO,
-		       "cldc_getaddr: hostname is not FQDN: \"%s\"",
-		       thishost);
+		HAIL_INFO(log, "cldc_getaddr: hostname is not FQDN: \"%s\"",
+			thishost);
 		return -1;
 	}
 	s++;
 
 	dlen = strlen(s);
 	if (nlen + 1 + dlen + 1 > size) {
-		act_log(LOG_INFO,
-		       "cldc_getaddr: domain is too long: \"%s\"", s);
+		HAIL_INFO(log, "cldc_getaddr: domain is too long: \"%s\"", s);
 		return -1;
 	}
 
@@ -161,8 +153,8 @@ static void push_host(GList **host_list, struct cldc_host *hp_in)
  * This is not reentrant.  Better be called before any other threads
  * are started.
  */
-int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
-		 void (*act_log)(int prio, const char *fmt, ...))
+int cldc_getaddr(GList **host_list, const char *thishost,
+		struct hail_log *log)
 {
 	enum { hostsz = 64 };
 	char cldb[hostsz];
@@ -183,7 +175,7 @@ int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
 	 * is a lookup in the DNS root (probably the standard-compliant
 	 * dot between "_cld" and "_udp" hurts us here).
 	 */
-	if (cldc_make_fqdn(cldb, hostsz, "_cld._udp", thishost, act_log) != 0)
+	if (cldc_make_fqdn(cldb, hostsz, "_cld._udp", thishost, log) != 0)
 		return -1;
 
 do_try_again:
@@ -191,12 +183,11 @@ do_try_again:
 	if (rc < 0) {
 		switch (h_errno) {
 		case HOST_NOT_FOUND:
-			act_log(LOG_INFO,
-				"cldc_getaddr: No _cld._udp SRV record");
+		  HAIL_INFO(log, "cldc_getaddr: No _cld._udp SRV record");
 			return -1;
 		case NO_DATA:
-			act_log(LOG_INFO,
-				"cldc_getaddr: Cannot find _cld._udp SRV record");
+			HAIL_INFO(log, "cldc_getaddr: Cannot find _cld._udp "
+				"SRV record");
 			return -1;
 		case TRY_AGAIN:
 			if (search_retries-- > 0)
@@ -204,8 +195,7 @@ do_try_again:
 			/* fall through */
 		case NO_RECOVERY:
 		default:
-			act_log(LOG_INFO,
-				"cldc_getaddr: res_search error (%d): %s",
+			HAIL_INFO(log, "cldc_getaddr: res_search error (%d): %s",
 				h_errno, hstrerror(h_errno));
 			return -1;
 		}
@@ -213,13 +203,13 @@ do_try_again:
 	rlen = rc;
 
 	if (rlen == 0) {
-		act_log(LOG_INFO,
-			"cldc_getaddr: res_search returned empty reply");
+		HAIL_INFO(log, "cldc_getaddr: res_search returned "
+			"empty reply");
 		return -1;
 	}
 
 	if (ns_initparse(resp, rlen, &nsb) < 0) {
-		act_log(LOG_INFO, "cldc_getaddr: ns_initparse error");
+		HAIL_INFO(log, "cldc_getaddr: ns_initparse error");
 		return -1;
 	}
 
@@ -237,42 +227,32 @@ do_try_again:
 		case ns_t_srv:
 			rrlen = ns_rr_rdlen(rrb);
 			if (rrlen < 8) {	/* 2+2+2 and 2 for host */
-				if (verbose) {
-					act_log(LOG_DEBUG,
-						"cldc_getaddr: SRV len %d",
-						rrlen);
-				}
+				HAIL_DEBUG(log, "cldc_getaddr: SRV len %d",
+					rrlen);
 				break;
 			}
 			p = ns_rr_rdata(rrb);
 			rc = dn_expand(resp, resp+rlen, p+6, hostb, hostsz);
 			if (rc < 0) {
-				if (verbose) {
-					act_log(LOG_DEBUG, "cldc_getaddr: "
-					       "dn_expand error %d", rc);
-				}
+				HAIL_DEBUG(log, "cldc_getaddr: "
+					"dn_expand error %d", rc);
 				break;
 			}
 			if (rc < 2) {
-				if (verbose) {
-					act_log(LOG_DEBUG, "cldc_getaddr: "
-					       "dn_expand short %d", rc);
-				}
+				HAIL_DEBUG(log, "cldc_getaddr: "
+					"dn_expand short %d", rc);
 				break;
 			}
 
 			if (cldc_saveaddr(&hp, ns_get16(p+0),
 					  ns_get16(p+2), ns_get16(p+4),
-					  rc, hostb, verbose, act_log))
+					  rc, hostb, log))
 				break;
 
 			push_host(host_list, &hp);
 			break;
 		case ns_t_cname:	/* impossible, but */
-			if (verbose) {
-				act_log(LOG_DEBUG,
-					"CNAME in SRV request, ignored");
-			}
+			HAIL_DEBUG(log, "CNAME in SRV request, ignored");
 			break;
 		default:
 			;
diff --git a/tools/cldcli.c b/tools/cldcli.c
index 23cba99..8eeee72 100644
--- a/tools/cldcli.c
+++ b/tools/cldcli.c
@@ -97,7 +97,6 @@ struct timer {
 };
 
 static unsigned long thread_running = 1;
-static int debugging;
 static GList *host_list;
 static char clicwd[CLD_PATH_MAX + 1] = "/";
 static int to_thread[2], from_thread[2];
@@ -136,6 +135,11 @@ static void applog(int prio, const char *fmt, ...)
 	va_end(ap);
 }
 
+static struct hail_log cli_log = {
+	.func = applog,
+	.verbose = 0,
+};
+
 static gint timer_cmp(gconstpointer a_, gconstpointer b_)
 {
 	const struct timer *a = a_;
@@ -531,7 +535,7 @@ static void handle_user_command(void)
 
 	read_to_thread(&creq, sizeof(creq));
 
-	if (debugging)
+	if (cli_log.verbose)
 		switch (creq.cmd) {
 		case CREQ_CD:
 		case CREQ_CAT:
@@ -1236,7 +1240,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
 	switch(key) {
 	case 'D':
 		if (atoi(arg) >= 0 && atoi(arg) <= 2)
-			debugging = atoi(arg);
+			cli_log.verbose = atoi(arg);
 		else {
 			fprintf(stderr, "invalid debug level: '%s'\n", arg);
 			argp_usage(state);
@@ -1304,7 +1308,7 @@ int main (int argc, char *argv[])
 			return 1;
 		}
 		hostb[hostsz-1] = 0;
-		if (cldc_getaddr(&host_list, hostb, debugging, applog)) {
+		if (cldc_getaddr(&host_list, hostb, &cli_log)) {
 			fprintf(stderr, "Unable to find a CLD host\n");
 			return 1;
 		}
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe hail-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Fedora Clound]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux