Skip to contentSkip to conversation

CLD: Whole hog on applog

PATCH Applied Pete Zaitcev 2 participants 2 messages Aug 12, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 CLD: Whole hog on applog

We abandon the wasteful strategy of gradual changes and simply change to applog-style API wholesale, to put the whole issue behind. Applications need to be rebuilt after new cld-devel is installed.

include/cldc.h +3 -5
index 712e7c7..8c2bde5 100644
@@ -78,7 +78,6 @@ struct cldc_ops {
 				const void *buf, size_t buflen);
 	void		(*event)(void *private, struct cldc_session *,
 				 struct cldc_fh *, uint32_t);
-	void		(*printf)(const char *fmt, ...);
 	void		(*errlog)(int prio, const char *fmt, ...);
 };
 
@@ -89,8 +88,7 @@ struct cldc_session {
 	bool		verbose;
 
 	const struct cldc_ops *ops;
-	void		(*act_log)(struct cldc_session *,
-				   int prio, const char *fmt, ...);
+	void		(*act_log)(int prio, const char *fmt, ...);
 	void		*private;
 
 	uint8_t		addr[64];		/* server address */
@@ -211,13 +209,13 @@ extern bool cldc_levent_timer(void *private, bool add,
 
 /* cldc-dns */
 extern int cldc_getaddr(GList **host_list, const char *thishost, bool verbose,
-		 void (*act_log)(const char *fmt, ...));
+		 void (*act_log)(int prio, const char *fmt, ...));
 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)(const char *fmt, ...));
+			 void (*act_log)(int prio, const char *fmt, ...));
 
 static inline bool seqid_after_eq(uint64_t a_, uint64_t b_)
 {
lib/cldc-dns.c +29 -26

166 lines not on this page · raw message

lib/cldc.c +32 -61

227 lines not on this page · raw message

tools/cldcli.c +6 -13
index b2a0c02..2375ef4 100644
@@ -144,12 +144,14 @@ static void errc_msg(struct cresp *cresp, enum cle_err_codes errc)
 	strcpy(cresp->msg, names_cle_err[errc]);
 }
 
-static void app_log(const char *fmt, ...)
+static void applog(int prio, const char *fmt, ...)
 {
+	char buf[200];
 	va_list ap;
 
 	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
+	vsnprintf(buf, 200, fmt, ap);
+	fprintf(stderr, "%s\n", buf);
 	va_end(ap);
 }
 
@@ -780,20 +782,11 @@ static void cld_p_event(void *private, struct cldc_session *sess,
 	fprintf(stderr, "FIXME: event\n");
 }
 
-static void cld_p_log(const char *fmt, ...)
-{
-	va_list ap;
-
-	va_start(ap, fmt);
-	vfprintf(stderr, fmt, ap);
-	va_end(ap);
-}
-
 static struct cldc_ops cld_ops = {
 	.timer_ctl	= cld_p_timer_ctl,
 	.pkt_send	= cld_p_pkt_send,
 	.event		= cld_p_event,
-	.printf		= cld_p_log,
+	.errlog		= applog,
 };
 
 static gpointer cld_thread(gpointer dummy)
@@ -1307,7 +1300,7 @@ int main (int argc, char *argv[])
 			return 1;
 		}
 		hostb[hostsz-1] = 0;
-		if (cldc_getaddr(&host_list, hostb, debugging, app_log)) {
+		if (cldc_getaddr(&host_list, hostb, debugging, applog)) {
 			fprintf(stderr, "Unable to find a CLD host\n");
 			return 1;
 		}
Applied
#1 lore raw
Quoted 5 lines · Pete Zaitcev

We abandon the wasteful strategy of gradual changes and simply change to applog-style API wholesale, to put the whole issue behind. Applications need to be rebuilt after new cld-devel is installed.

applied