Skip to contentSkip to conversation

CLD: factor timers out into a library

PATCH In review Pete Zaitcev 2 participants 6 messages Nov 29, 2009 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 CLD: factor timers out into a library

From: Jeff Garzik <[email protected]>

Move timer_init and friends so that they can be used by test/*.

---
 include/Makefile.am |    2 
 include/libtimer.h  |   34 ++++++++++++++++
 lib/.gitignore      |    2 
 lib/Makefile.am     |    2 
 lib/libtimer.c      |   83 ++++++++++++++++++++++++++++++++++++++++
 server/Makefile.am  |    3 -
 server/cld.h        |   25 ------------
 server/util.c       |   87 ------------------------------------------
 8 files changed, 125 insertions(+), 113 deletions(-)

commit 92da6100e5803526ce8acc907c23a5dba3aee758

Author: Master <[email protected]>
Date:   Sat Nov 28 23:12:31 2009 -0700

The libtimer by jgarzik.

include/Makefile.am +1 -1
index 06e35a6..f7539dd 100644
@@ -1,5 +1,5 @@
 
-EXTRA_DIST = cld-private.h
+EXTRA_DIST = cld-private.h libtimer.h
 
 include_HEADERS = cldc.h cld_msg.h
 
include/libtimer.h new file +34 -0
new file mode 100644
index 0000000..aedaea0
@@ -0,0 +1,34 @@
+
+#ifndef __LIBTIMER_H__
+#define __LIBTIMER_H__
+
+#include <stdbool.h>
+#include <string.h>
+#include <time.h>
+
+struct timer {
+	bool			fired;
+	bool			on_list;
+	void			(*cb)(struct timer *);
+	void			*userdata;
+	time_t			expires;
+	char			name[32];
+};
+
+extern void timer_add(struct timer *timer, time_t expires);
+extern void timer_del(struct timer *timer);
+extern time_t timers_run(void);
+
+static inline void timer_init(struct timer *timer, const char *name,
+			      void (*cb)(struct timer *),
+			      void *userdata)
+{
+	memset(timer, 0, sizeof(*timer));
+	timer->cb = cb;
+	timer->userdata = userdata;
+	strncpy(timer->name, name, sizeof(timer->name));
+	timer->name[sizeof(timer->name) - 1] = 0;
+}
+
+#endif /* __LIBTIMER_H__ */
+
lib/.gitignore +2 -0
index 9eaa296..dddcc4c 100644
@@ -6,5 +6,7 @@ libcldc.la
 libcldc-uninstalled.pc
 libcldc.pc
 
+libtimer.a
+
 .libs
 
lib/Makefile.am +2 -0
index 5b042ef..68be429 100644
@@ -16,6 +16,8 @@ libcldc_la_LDFLAGS = \
 	-no-undefined \
 	-export-symbols-regex "^[^_].*"
 
+noinst_LIBRARIES	= libtimer.a
+
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libcldc.pc
 
lib/libtimer.c new file +83 -0

83 lines not on this page · raw message

server/Makefile.am +2 -1
index 929a3fd..d099b4a 100644
@@ -8,7 +8,8 @@ sbin_PROGRAMS	= cld cldbadm
 cld_SOURCES	= cldb.h cld.h \
 		  ../lib/common.c \
 		  cldb.c msg.c server.c session.c util.c
-cld_LDADD	= @CRYPTO_LIBS@ @GLIB_LIBS@ @DB4_LIBS@ @ARGP_LIBS@
+cld_LDADD	= ../lib/libtimer.a \
+		  @CRYPTO_LIBS@ @GLIB_LIBS@ @DB4_LIBS@ @ARGP_LIBS@
 
 cldbadm_SOURCES	= cldb.h cldbadm.c
 cldbadm_LDADD	= @CRYPTO_LIBS@ @GLIB_LIBS@ @DB4_LIBS@ @ARGP_LIBS@
server/cld.h +1 -24
index da26862..05c93ad 100644
@@ -26,8 +26,8 @@
 #include <glib.h>
 #include "cldb.h"
 #include <cld_msg.h>
+#include <libtimer.h>
 
-struct timer;
 struct client;
 struct session_outpkt;
 
@@ -40,15 +40,6 @@ enum {
 	SFL_FOREGROUND		= (1 << 0),	/* run in foreground */
 };
 
-struct timer {
-	bool			fired;
-	bool			on_list;
-	void			(*cb)(struct timer *);
-	void			*userdata;
-	time_t			expires;
-	char			name[32];
-};
-
 struct client {
 	struct sockaddr_in6	addr;		/* inet address */
 	socklen_t		addr_len;	/* inet address len */
@@ -176,20 +167,6 @@ extern void applog(int prio, const char *fmt, ...);
 extern int write_pid_file(const char *pid_fn);
 extern void syslogerr(const char *prefix);
 extern int fsetflags(const char *prefix, int fd, int or_flags);
-extern void timer_add(struct timer *timer, time_t expires);
-extern void timer_del(struct timer *timer);
-extern time_t timers_run(void);
-
-static inline void timer_init(struct timer *timer, const char *name,
-			      void (*cb)(struct timer *),
-			      void *userdata)
-{
-	memset(timer, 0, sizeof(*timer));
-	timer->cb = cb;
-	timer->userdata = userdata;
-	strncpy(timer->name, name, sizeof(timer->name));
-	timer->name[sizeof(timer->name) - 1] = 0;
-}
 
 #ifndef HAVE_STRNLEN
 extern size_t strnlen(const char *s, size_t maxlen);
server/util.c +0 -87

99 lines not on this page · raw message

#2 lore raw
In reply to Pete Zaitcev
Quoted 5 lines · Pete Zaitcev

From: Jeff Garzik<[email protected]>

Move timer_init and friends so that they can be used by test/*.

hmmm... cld now segfaults reliably in koji:
http://koji.fedoraproject.org/koji/taskinfo?taskID=1836079
http://koji.fedoraproject.org/koji/taskinfo?taskID=1836084

Both of those are cld build attempts. The second build attempt gives a db4-related error before dying, too.

Jeff

#5 lore raw
Quoted 10 lines · Jeff Garzik
Quoted 7 lines · Pete Zaitcev
Quoted 2 lines · On Sun, 29 Nov 2009 06:11:44 -0500 Jeff Garzik<[email protected]> wrote:

hmmm... cld now segfaults reliably in koji:
http://koji.fedoraproject.org/koji/taskinfo?taskID=1836079

Curious. It works fine here, of course (make distcheck). Did you try to build locally?

Tests work fine locally. They fail 100% of the time in koji.

This is an F13 buildroot, right? There may be some difference. I must admit I only tested on F12. I'll handle this and keep you updated.

-- Pete